How to Insert a TextBox value in to Sql database using
VB.Net coding?

Answer Posted / deepmala soni

Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim ra as Integer
'integer holds the number of records inserted
myConnection = New SqlConnection
("server=localhost;uid=sa;pwd=;database=Hospital")
'you need to provide password for sql server
myConnection.Open()
mycommand = New SqlCommand("INSERT INTO Patient
(ID,Name,address,DateofBirth,Gender,Phone,Emergencycontact,D
ateofRegistration) VALUES('" + lblid.Text + "','" +
txtname.Text + "','" + rtxtaddress.Text + "','" +
DateTimePicker1.Text + "','" + cmbgender.Text + "','" +
txtphone.Text + "','" + txtemcon.Text + "','" +
txtdoreg.Text + "')", myconnection)
ra=myCommand.ExecuteNonQuery()
MessageBox.Show("New Row Inserted" & ra)
myConnection.Close()

Is This Answer Correct ?    46 Yes 18 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is it necessary to have SQL server installed in your computer in order to create a service based database in vb.net?

2088


When do you use virutal keyword?

792


Explain how can we remove handlers at run time?

749


What are the differences between c# and visual basic.net?

779


What are the different variables in vb.net?

724


Explain jit?

746


Which classes a dll can contain?

747


What is the difference between convert.tostring and i.tostring method?

788


How do you use two datareaders at the same time in a vb.net windows application ?

807


What is the feature anonymous type?

711


How do you define a read only property in a class module?

724


Explain an assembly?

736


i am attending to US consulate i kept my projects on vb.net ,please help me what questions will be ask on vb.net in us consulate

2141


What is internal keyword in .net framework?

834


Write the role of new keyword?

854