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

Explain jagged array in vb.net?

751


What is the use of internal keyword?

770


Explain convert.tostring and i.tostring method?

708


Write program in VB.Net with SQL Server and Crystal Reports to develop a small windows application to add,edit,save, search and print Employee Information and send sourcecode as zip file. empcode : .............. empname : .............. dateofjoin : dd/mm/yyyy dateofbirth : dd/mm/yyyy TableName: EmpMaster EmpCode EmpName DOB DOJ TableName: EmpDocs EmpCode DocNo DocName ExpDate

2404


What is the feature which is common to all .net languages?

705


Explain what observations between vb.net and vc#.net?

735


Explain public assembly?

728


Can you please explain the difference between dispose and finalize()?

696


What is the difference between system.applicationexception class and system.systemexception?

903


What is the top .net class that everything is derived from?

833


What is the importance of a Button control?

1084


What are the technology areas that microsoft.net contains?

771


What are the different types of a stream?

747


What are the features present in vb 2005?

752


When do you use virutal keyword?

774