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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / 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

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

Answer / anusuya

dim con as new sqlconnection
dim da as sqldataadapter
dim ds as new dataset
dim str as string

con.connectionstring="server=localhost;uid=sa;pwd=;database=
Hospital"
con.open
str="insert into patient values('" & lblid.Text & "','" &
txtname.Text & "','" & rtxtaddress.Text & "','" &
DateTimePicker1.Text & "','" & cmbgender.Text & "','" &
txtphone.Text & "','" & txtemcon.Text & "','" &
txtdoreg.Text &"')"
da=new sqldataadpter(str,con)
da.fill(ds,"patient")
msgbox "New Row inserted"
con.close

Is This Answer Correct ?    30 Yes 24 No

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

Answer / dinesh

Imports System.Configuration
Imports System.Data.SqlClient

Public Class Form1
Dim objcon As SqlConnection
Dim objcmd As SqlCommand

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
objcon.Open()
objcmd = New SqlClient.SqlCommand("insert into customer_master(First_Name,Last_Name,Address,contact_number,email_id)values('" & TextBox1.Text.Trim & "','"& TextBox2.Text.Trim &"','"& TextBox3.Text.Trim &"','" & TextBox5.Text.Trim & "','" & TextBox7.Text.Trim & "')", objcon)
Dim i As Integer = objcmd.ExecuteNonQuery()
If (i > 0) Then
MsgBox("Customer saved successfully!")
Else
MsgBox("Failed to save Customer!")
End If
objcon.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Is This Answer Correct ?    8 Yes 6 No

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

Answer / joe

Try Something Like This:

sqCmd.CommandText = "INSERT INTO [RF_DB].[dbo].[RFID_TABLE]
Values('" & textbox1.text & "', '" & textbox2.text & "','" &
textbox3.text & "')"

<A
HREF="http://www.difficulty9.com/blog/8-sql-insert-multiple-values.aspx">Check
The Blog</A>

Is This Answer Correct ?    3 Yes 10 No

Post New Answer

More VB.NET Interview Questions

What are the advantages of an assembly?

0 Answers  


What is the difference between manifest and metadata?

0 Answers  


What is the difference between Abstract Classes and Interfaces? Give the answer as a table format....

5 Answers  


hello friends, I have created a animated button in VB.NET. As its dll file coding can be viewed and also copied to some other location. So my question is how can I protect the Dll file of the animated button so that noone can access it. Any idea about this???????? Thanks Rekha

3 Answers  


How to achieve Polymorphism in VB.Net?

0 Answers  


What is a literal control?

0 Answers  


Explain the difference between web.config and machine.config and where it will be ?

0 Answers  


ColumnMapping belongs to which namespaces?

1 Answers  


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

0 Answers  


What are the various open source tool available for VB.NET?

0 Answers  


How do you do multithreading application in VB ?

4 Answers   Satyam,


What is global assembly cache (gac)?

0 Answers  


Categories