Sub loadtodgv()
Dim sqlquery As String = "select * from nursery"
Dim sqlcommand As New OleDbCommand
Dim sqladapter As New OleDbDataAdapter
Dim table As New DataTable
With sqlcommand
.CommandText = sqlquery
.Connection = conn
.ExecuteNonQuery()
End With
With sqladapter
.SelectCommand = sqlcommand
.Fill(table)
End With
DataGridView1.Rows.Clear()
For i = 0 To table.Rows.Count - 1
With DataGridView1
.Rows.Add(table.Rows(i)("regno"), table.Rows(i)("rollno"), table.Rows(i)("nepali(writing)"), table.Rows(i)("nepali(oral)"), table.Rows(i)("maths(writing1)"), table.Rows(i)("maths(oral)"), table.Rows(i)("maths(writing2)"), table.Rows(i)("english(writing)"), table.Rows(i)("english(oral)"), table.Rows(i)("physical_edu(oral)"), table.Rows(i)("creative(oral)"))
End With
Next
End Sub
Private Sub btndel_nursery_Click(sender As Object, e As EventArgs) Handles btndel_nursery.Click
For i = 0 To DataGridView1.Rows.Count - 1
Dim deleterows As String = DataGridView1.SelectedRows(i).Cells(0).Value.ToString
Dim sqlquery As String = "delete from nursery where regno=" & deleterows & ""
Dim sqlcommand As New OleDbCommand
With sqlcommand
.CommandText = sqlquery
.Connection = conn
.ExecuteNonQuery()
End With
Next
loadtodgv()
End Sub
End Class
sushilsth
0
Light Poster
Recommended Answers
Jump to PostI think you shouldn't use .executenonquery (see: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executenonquery.aspx) but .executereader (see: http://msdn.microsoft.com/en-us/library/9kcbe65k.aspx).
Jump to PostCan't you get any information in debugmode? What parameter is missing? Try to find an ADO.Net example, read some ADO.Net documentation; maybe you can find some clues for use. The way you use it, is somewhat compact. Usually it is spread over some layers of code. Good luck
All 6 Replies
sushilsth
0
Light Poster
C#Jaap
5
Junior Poster in Training
sushilsth
0
Light Poster
C#Jaap
5
Junior Poster in Training
scudzilla
32
Junior Poster
sushilsth
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.