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

Explain how to store decimal data in .net?

0 Answers  


Explain how can we remove handlers at run time?

0 Answers  


what are the advantages and diadvantages of active reports over crystal reports ?

1 Answers   IBM, Kotak,


What languages does the .net framework support?

0 Answers  


Explain some of the exclusive features which are present in vb?

0 Answers  






How a base class method is hidden?

0 Answers  


What are different types of jit ?

0 Answers  


how to call a list box on the text if some one send me the code for it

1 Answers  


Why do we use byref keyword in vb.net?

0 Answers  


Explain about delegate?

0 Answers  


Explain private assembly?

0 Answers  


Write a program that would find the nth term of a geometric progression, given the value of first term and common ratio. Any inbuilt function that the language provides for calculating exponent should not be used.

0 Answers  


Categories