How to Insert a TextBox value in to Sql database using
VB.Net coding?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
What are the advantages of an assembly?
What is the difference between manifest and metadata?
What is the difference between Abstract Classes and Interfaces? Give the answer as a table format....
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
How to achieve Polymorphism in VB.Net?
What is a literal control?
Explain the difference between web.config and machine.config and where it will be ?
ColumnMapping belongs to which namespaces?
Explain what observations between vb.net and vc#.net?
What are the various open source tool available for VB.NET?
How do you do multithreading application in VB ?
What is global assembly cache (gac)?