VB.NET Database Tutorial - INSERT Records Into a Microsoft SQL Database (PART 3) (Visual Basic .NET)

VB.NET Database Tutorial - INSERT Records Into a Microsoft SQL Database (PART 3) (Visual Basic .NET)

VB Toolbox

10 лет назад

53,176 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@ayowhat6139
@ayowhat6139 - 14.03.2020 22:38

i will love u my guyyyyyyyyyy

Ответить
@ziadjunied7261
@ziadjunied7261 - 22.03.2018 04:23

Thanks

Ответить
@samuelnatamihardja2570
@samuelnatamihardja2570 - 09.10.2016 14:13

hi.. i'm catching up your videos, .. but in my case, i want to insert data that having primary key data with formated data (ex. A001). how can i get the latest number? please help me.. thanks.. btw thanks alot for the video

Ответить
@ahmedabbas6758
@ahmedabbas6758 - 01.08.2016 23:28

Hi sir , I apply every steps shown in the Tutorial but i am using local -based SQL database , and my problem is data dose not be ,saved in table after inserting , but it shown in application , then after i restart my application the data also disappear what is the problem ?

Ответить
@lyawileh.a8741
@lyawileh.a8741 - 26.07.2016 06:51

A good instructor indeed. Thanks very much pro VB tutor.

Ответить
@art7148
@art7148 - 10.05.2016 09:16

Do you know how to solve Duplicating/repeating Line of records in details section .. Using multiple sql query... (inner join 4 tables)

Ответить
@andrewbowles9931
@andrewbowles9931 - 19.04.2016 10:58

Hi I have a question
So I have used you lecture as a template and added 9 items to the database the private sub on "sqlcontrol" is otherwise exactly as your but in the form that I have created to enter the details even though I included the line "Dim SQL As New SQLControl" I get the message that AddMember is not a member of SQlControl my version of the two pieces of text are below - Have you any ideas as to why its underlined and not recognised please ?

Public Sub AddMember(Title As String, Firstname As String, Surname As String, HouseNo As String, PostCode As String, MobileNo As String, Email As String, Regno As String, Newsletter As Integ)
Try
Dim strInsert As String = "INSERT INTO Customer(Title , Firstname , Surname , HouseNo , PostCode , MobileNo , Email , Regno , Newsletter) " &
"VALUES (" &
"'" & Title & "'," &
"'" & Firstname & "'," &
"'" & Surname & "'," &
"'" & HouseNo & "'," &
"'" & PostCode & "'," &
"'" & MobileNo & "'," &
"'" & Email & "'," &
"'" & Regno & "'," &
"'" & Newsletter & "' "
MsgBox(strInsert)

SQLCon.Open()
SQLCmd = New SQLCommand(strInsert, SQLCon)

SQLCmd.ExecuteNonQuery()

SQLCon.close()

Catch ex As Exception
MsgBox(ex.message)
End Try
End Sub


End Class

Public Class AddUser
Dim SQL As New SQLControl

Private Sub btnSaveNewUser_Click(sender As Object, e As EventArgs) Handles btnSaveNewUser.Click
'Confirm that they are not already registered
Sql.RunQuery("Select * From Customer Where customer.firstname = '" & txtFname.Text & "' " & "Customer.Surname = '" & txtSurname.Text & "' ")

If Sql.SQLDataset.Tables(0).Rows.Count > 0 Then
MsgBox("User is Already Registered!")
Exit Sub
Else
CreateUser()
End If
End Sub

Public Sub CreateUser()
If Len(txtFname.Text) >= 3 And Len(txtSurname.Text) >= 4 And Len(txtSurname.Text) >= 6 And Len(txtHouseNo.Text) > 0 And Len(txtPostCode.Text) > 7 And Len(txtMobileNo.Text) > 7 And Len(txtEmail.Text) > 7 And Len(txtRegNo.Text) > 2 Then
'Newletter Checkbox
Dim Newsletter As Integer
If rbNewsletter.Checked = True Then Newsletter = 1 Else Newsletter = 0

'Add new user to database
SQL.AddMember(txtTitle.Text, txtFname.Text, txtSurname.Text, txtHouseNo.Text, txtPostCode.Text, txtMobileNo.Text, txtEmail.Text, txtRegNo.Text, rbNewsletter.Text)
Else
MsgBox("Please make sure you have filled in ALL Fields Correctly!")
Exit Sub
End If
End Sub
End Class

Also I have saved the file and in the build pull down tried rebuilding it ?

Ответить
@mashaandbeer1472
@mashaandbeer1472 - 16.04.2016 22:38

Useful Tutorial. Thanks Man!!.

Ответить
@eniyook5848
@eniyook5848 - 19.03.2016 05:32

Hi.

I have a question.

I have three tables in my database. In your tabpage2, you will be able to create new record right? In your tutorial, you'll only be able to create a new record in the first table only. How am I be able to create new record for the second or third or other table? Or maybe is it okay if there's a combo box in tha tabpage2 where you can choose on what table you will add your new record? Please answer. Thanks a lot.

Ответить
@renejamis2149
@renejamis2149 - 29.12.2015 08:14

I'm in need of inserting records into TABLE2 which has a relationship established to TABLE1. In a simplistic example:
TABLE1
StudentID int _PK
Name VarChar(20), null

TABLE2
ClassID int _PK
StudentID int _FK
Class Name VarChar(15), null

Any assistance you could provide would be greatly appreciated. I have looked around buy YT doesn't have any related videos to what I'm attempting to do. Thanks in advance.

Ответить
@rjbarretto5606
@rjbarretto5606 - 11.12.2015 23:21

hi sir, i have a question...

i have a 4 column named item, description, model/Serial and quantity.
if i want to insert into the said 4 column it will check if the items exist and if it does,
it will just add to the quantity.

here's my code:

SQL.AddParams("@item", txtAddItem.Text)
SQL.AddParams("@desc",txtdescription.Text)
SQL.AddParams("@model", txtModSerial.Text)
SQL.AddParams("@Qty", txtQuantity.Text)

SQL.ExecQuery("SELECT * FROM Item_Main WHERE Itm_Code=@item")

If SQL.SQLDs.Tables(0).Rows.Count > 0 Then

SQL.ExecQuery("UPDATE Item_Main " & _
"SET Qty = Qty + @qty" & _
"WHERE Itm_Description=@desc and Itm_ModSerial=@model ")

it doesn't give me an error though, but it doesn't add my quantity column.

hope you can help me with this...
thank you soo much..

Ответить
@TheSedrick18
@TheSedrick18 - 06.12.2015 11:10

Hello There !

I have a question,

How to Insert data into two table with same command ? Help me plsss :) THNX !

Ответить
@plaha2646
@plaha2646 - 22.11.2015 23:03

ive been trying to save a label but it wont work it resets every time i push the load button?? this is my script:

load button:
lbl_cash.Text = My.Settings.Savecash
lbl_cps.Text = My.Settings.Savecps

Save button:
My.Settings.Savecash = lbl_cash.Text
My.Settings.Savecps = lbl_cps.Text

Ответить
@sunniaccount1213
@sunniaccount1213 - 04.10.2015 17:41

Really good tutorials, I have downloaded the source files but I have noticed that there is no database inside the files.  could please provide me a link where I can download the files with the database.  Thank you.  I am having problem with sql management 2014/ SQL 2014  as it has many changes and wont open previous Microsoft sql databases, it ask for update and I do that and then something else is wrong with that database ,  not nice on part of Microsoft, spent few hours trying resolve it.  That I would appreciate a database with the project files.

Ответить
@bachphi1
@bachphi1 - 20.09.2015 06:07

WHERE IS THE LINK? YOIU SAID SO.

Ответить
@waqasahmed9065
@waqasahmed9065 - 10.09.2015 18:38

HI
HOPE U HAVE GOOD DAY.
ITS AN AWSUM TUTORIAL FOR BIGNNERS LIKE ME.ITS REALLY HELP ME ALOT.
BUT I HAVE AN QUESTION MAY BE U CAN HELP ME ON IT.
HOW CAN U BLOCK THE EMPTY ADD FROM TEXTBOXES ?
THANKS ALOT AGAIN
BEST OF LUCK

Ответить
@donvillafuerte
@donvillafuerte - 02.09.2015 11:51

This is the best tutorial i've ever watched. Seriously! Thanks a lot!

Ответить
@rpgrahamla
@rpgrahamla - 19.08.2015 23:59

How do I get the source code to the series of videos?  They are extremely instructive, but the complete source code printed out to study would be even more helpful.

thanks,

Ответить
@evadtrent5607
@evadtrent5607 - 19.08.2015 13:28

Please share the link to the source  code.

Ответить
@royjalbout
@royjalbout - 22.02.2015 04:15

hello, great work thank you so much

everything is ok with your code but i have a textbox to enter birthdate how can i insert the date to the sql server

am getting an error incorrect syntax near 'MM-dd-yyyy'

any help?????

Ответить
@MrJColeman1987
@MrJColeman1987 - 29.09.2014 09:37

YES, I got this to work too!!

Ответить
@jamesniven1078
@jamesniven1078 - 10.09.2014 21:17

VB Toolbox, great tutorials indeed, as a raw beginner I am learning a lot.
Where can I download the VB code you type in within your videos?

Ответить
@dmcd1610
@dmcd1610 - 03.07.2014 04:48

Your tutorials are the best I have seen.  Insert Records into SQL DB Part 3 is exactly what I needed for my project.  I am building an inventory database to keep track of all the laptops, servers and other equipment we have assigned to locations all over the US.  The last feature I am trying to add is the ability to copy the data fields on the form and create a new record in the database.  The idea is a laptop is re-issued to a new user, we want to keep history and make a new record for the new user.  For data entry ease, would be nice to copy the fields that remain the same and then the data entry person can update just the changed fields.  

I followed your tutorial very carefully and have your code working properly on a test form within my project.  However when I apply the same code to my working form, I get an "error converting data type varchar to numeric".    

I even tried copying just a few fields, and then just the first field and still get the error.  My data types are varchar, numeric and datetime.  Since all fields are like:   ByVal AssetTag As String,  I can't figure out why/ where the problem is.  

My code runs past the MsgBox(srtInsert) and displays the column names and the  values, but I don't see all of the values in the message.  The values looks like this:  ('3337','','LPT587','DPV9G11','','','',  and so on.  (Looks like some of the field values are missing.)  Then the error message is displayed.

 Is the problem that is is not reading the numeric values properly that should be displayed in the messagebox?  The values that appear to be missing are the selected index values for combo boxes.  I tested for this in my test form and had no problem so I am kind of stuck.

Any ideas would be very much appreciated.

Ответить
@lykagutierrez122
@lykagutierrez122 - 24.06.2014 19:14

Hello. I have a question regarding on how to add data into sql server and view it into the datagrid as well. Hope you'll find time reading my comment here. :) Thanks

Ответить
@jkozzen6794
@jkozzen6794 - 05.06.2014 12:59

do you have an entity framework tutorial ?

Ответить
@thanosarampatzis7164
@thanosarampatzis7164 - 26.05.2014 02:20

Hey I wanna make a database with two columns "Code" and "Quantity". So if column Code contains a specific value and a quantity when Im gonna insert again the same code with different quantity I want the new quantity to add it to the last one. How can I do that? O_o

Ответить
@TheJoker0
@TheJoker0 - 01.05.2014 15:19

Hi, Thanks for all! your tutorials are awesome. 

All are very helpful tutorial, but there is some questions that i need your help for,
How do I create my "INSERT INTO" to allow both valid dates or NULL values to be used when inserting into an Access database. I have spent hours on this, including saving the text fields to variants, and all sorts of other things.  it's  an emergency case I will appreciate very your help Thank you :)

Ответить
@tenstepsfromhell
@tenstepsfromhell - 01.05.2014 06:44

This tutorial has been very helpful to my university project. I'm highly grateful. 

Ответить
@martomystery
@martomystery - 22.04.2014 14:46

I get error index out of range on statement below.What myt be wrong?
If Sql.SqlDataset.Tables(0).Rows.Count <> 0 Then

Ответить
@tigrishabeeb6796
@tigrishabeeb6796 - 04.01.2014 05:08

Thanks a lot for those helpful tutorials,and you explain in a very nice or great and calm style,do u know that i have been googling the net for a year to look for classes tutorial!!,i am waiting to learn more from your fantastic videos.i need that very urgent and will be appreciated if you upload many and many of those great videos.thanks again for your help !!!

Ответить
@iammaxim1115
@iammaxim1115 - 03.01.2014 22:38

You have no idea how much this is helping me for work right now, amazing

Thank you

Ответить