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 + "')", mycon)ra=myCommand.ExecuteNonQuery()
MessageBox.Show("New Row Inserted" & ra)
myConnection.Close()

Is This Answer Correct ?    32 Yes 23 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain clr?

758


Did vb6 support multi-threading ?

737


What is static member?

768


What is misl code?

759


what is commom language runtime?

741


Explain convert.tostrin?

836


what is the advantage of option strict on?

795


my project run very wel in my sytem yhen i am deploying my project on client machine ,after deployment i run my project then it show " can no find server name " what i do .

1741


What is the use of assembly?

757


Which class allows an element to be accessed using unique key?

713


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

751


Can you please explain the difference between c# and vb.net?

817


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

712


What is the use of system.diagnostics.process class?

783


write a program to develop a graphic user interface application of marks book with students names and their names.the program should show the following options main menu,add student details,display student details,maximum mark and minimum mark.

1390