1
Answer

Delete, insert, update

Photo of mithil Malhotra

mithil Malhotra

14y
2.9k
1
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)

0
Photo of Ramesh Palanivel
NA 9.5k 138.7k 7y
HI Bhaskar,
 
Please refer this below URL for your reference,
 
http://www.c-sharpcorner.com/UploadFile/6b8651/read-excel-file-in-windows-application-using-C-Sharp/
 
Accepted
0
Photo of Ramesh Palanivel
NA 9.5k 138.7k 7y
Hi Baskar,
 
Can you share your screnn shot of error message 
0
Photo of Bhaskar Sharma
NA 12 166 7y

I am talking about the example on that URL , there it gives an exception on giving the name of sheet as the name of sheet becomes too long., so any solution for that

 
i.e OleDbDataAdapter oleAdpt = new OleDbDataAdapter("select * from [Sheet1$]", con);  
0
Photo of Ramesh Palanivel
NA 9.5k 138.7k 7y
Hi Baskar,
 
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item("Mention your sheet name")
//mention your excel sheet name
<span style="font-family: Roboto, sans-serif;"> </span>
0
Photo of Bhaskar Sharma
NA 12 166 7y

I have to upload a  specific sheet from a woorkbook how can i do that.