Delete, insert, update

May 24 2010 2:00 AM
Hii

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\
sqlexpress;Initial Catalog=Dataconnect;Integrated Security=True"
        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(strCommand, con)

            con.Open()

            cm.ExecuteNonQuery()

            MsgBox("Succesfully saved…")

        Catch ex As Exception

            MessageBox.Show(ex.Message, "Error")
            'MessageBox.Show(ex.InnerException, "Error")

        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

Answers (1)