i used this code to delete row from datagridview but it dosnt delete the selected row it delete the first row , where is the problem??
Dim sCommand As SqlCommand
Dim sAdapter As SqlDataAdapter
Dim sBuilder As SqlCommandBuilder
Dim sDs As DataSet
Dim sTable As DataTable
*****
Dim connectionString As String = "Data Source=HABOUSH-PC\SQLEXPRESS;Initial Catalog=TenderingSystem;Integrated Security=True"
Dim sql As String = "SELECT * FROM BOQDetailEntry"
Dim connection As New SqlConnection(connectionString)
connection.Open()
sCommand = New SqlCommand(sql, connection)
sAdapter = New SqlDataAdapter(sCommand)
sBuilder = New SqlCommandBuilder(sAdapter)
sDs = New DataSet()
sAdapter.Fill(sDs, "BOQDetailEntry")
sTable = sDs.Tables("BOQDetailEntry")
connection.Close()
BOQDetailEntryDGV.DataSource = sDs.Tables("BOQDetailEntry")
**********
Dim i As Integer
i = BOQDetailEntryDGV.CurrentRow.Index
If MessageBox.Show("Are You sure you want to delete " + BOQDetailEntryDGV(4, i).Value().ToString + " Entry ?", "Warning Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.OK Then
Try
BOQDetailEntryDGV.Rows.RemoveAt(BOQDetailEntryDGV.CurrentRow.Index)
sAdapter.Update(sTable)
'*******************************************&&&&********************************
Catch ex As Exception
MessageBox.Show("No record deleted")
End Try
End If
HibaPro -3 Junior Poster
G_Waddell 131 Posting Whiz in Training
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.