Hello. I am a beginner to programming. I would like to use a form to populate my sql database. Can somebody tell me where to find information on doing this? I have my database and I'm able to display the information from from the database but I don't know how to write to it. I would like to use vb.net.
thanks,

Recommended Answers

All 3 Replies

well If you know how to make a connection with the database which i think you do, because you are getting data from the db. to insert a new record is much easier.

lets say that we have a table like this
Person
Name
LastName
Address

Dim insertStatement  As String
insertStatement = "INSERT INTO Person (Name, LastName, Address) VALUES ('"+TextBox1.Text+"','"+TextBox2.Text+"','"+TextBox3.Text+"')"
Dim cmd As New System.Data.SqlClient.SqlCommand(insertStatement, Conne)
Conne.Open()
cmd.ExecuteNonQuery()
Conne.Close()

Which TextBox1.Text Contain the name or could be a string variable.
TextBox2.Text Contain the Last Name and TextBox3.Text the Address

And Conne is the connection already created.
hope that helps
regards.

Thanks a lot. This really helped out. Yes. I am connected. I just didn't know how to put information back into the database using a web form. I appreciate the help.

Glad to know you are in the road.

You can do this also replacing the textbox1.text in the insert statement by @name and so one and then add this line for every single parameter

cmdNcr.Parameters.Add("@name", SqlDbType.VarChar).Value = TextBox1.Text;

and so on.

Take care.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.