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

What are jagged arrays ?

572


Described strong typing and weak typing?

623


Explain the difference between an xml "fragment" and an xml "document."

502


How to run a dos command in vb.net?

610


Explain trace in vb.net?

518






What does assert() method do In VB.NET

530


Explain internal keyword in .net framework?

568


What are the types of generations in garbage collector?

529


So you know which dll is used for microsoft .net run time?

513


Tell us how many languages are supported by .net?

507


Explain the use of serialization and deserialization?

513


What are the different variables in vb.net?

518


Explain and brief about rapid application development tool?

588


Can we use Vb.Net and C# language simultaneously in one .Net application?

562


Explain enumerator?

523