I am new to VB.NET. I have created a database and a form Which has 5 fields. I am using This code to insert data into data base.
Sub insert()
Dim strCon As String = "Data Source=win-8mmefl12klc\
Dim con As New SqlClient.SqlConnection
Dim strCommand As String = "Insert into User1_t (name, address, phone, nationality, hsecry, puc, degree, post_graduation) values ('" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "','" & Me.TextBox3.Text & "','" & Me.TextBox4.Text & "','" & Me.TextBox5.Text & "','" & Me.TextBox6.Text & "','" & Me.TextBox7.Text & "','" & Me.TextBox8.Text & "')"
Try
con.ConnectionString = strCon
Dim cm As New SqlClient.SqlCommand(
con.Open()
cm.ExecuteNonQuery()
MsgBox("Succesfully saved…")
Catch ex As Exception
MessageBox.Show(ex.Message, "Error")
'MessageBox.Show(ex.
Finally
If con.State = ConnectionState.Open Then
con.Close()
End If
End Try
End Sub
Would any one suggest me how to delete record and update.
This is urgent as my project work is going on.........
Regard
Mithil
Albertto LiePosted May 24, 2010, 2:20 AM
so the delete record will be
delete from User1_t where name = TextBox1.Text
and the update will be
update User1_t set address = TextBox2.Text ( u can add more like " , phone = TextBox3.Text " ) where name = TextBox1.Text