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 |
ColumnMapping belongs to which namespaces?
Explain about the ruby interface generator?
What do you mean by Redim in VB.NET?
Explain an assembly and its use?
sql satement for 2nd maximum value
What are the advantages of an assembly?
In order to get assembly info whcih namespace we should import?
How do you use two datareaders at the same time in a vb.net windows application ?
give me code for selecting itemcode and correspondin vendor details wll displays in the gridview?
i could not run my application in any computers if i want to run it i have to install the full version of visual studio 2005. it is really hard and feel embarrassing in front of the people though i installed .net framework where goes wrong
What is the use of console application?
described weak typing?