幫我看下代碼出錯在那裡
Private Sub But_del_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles But_del.ClickDim objDataadapter As New SqlDataAdapter '填充數據
Dim objCommand As New SqlCommand '執行語法
Dim objDs As New DataSet '得到dataset連
Dim objBm As BindingManagerBase '綁定與管理數據成員對象
Dim objDatatable As DataTable '報表內存中的表
Try
If DataGridView1.RowCount <= 0 Then
MsgBox("請選擇需要刪除的資料")
Exit Sub
End If
If MsgBox("是否刪除" & DataGridView1.Columns(0).HeaderCell.Value.ToString & "為{" & DataGridView1.CurrentRow.Cells(0).Value.ToString & "}的這筆數據?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
'objDatatable.Rows(DataGridView1.CurrentRow.Index).Delete() '從本地刪除數據
For Each r As DataGridViewRow In DataGridView1.SelectedRows
If Not r.IsNewRow Then
DataGridView1.Rows.Remove(r)
End If
Next
'更改到表中
objDataadapter.Update(objDatatable.GetChanges)
objDatatable.AcceptChanges() ';接受更改
Else
Exit Sub
End If
Catch ex As Exception
MessageBox.Show(Err.ToString)
MessageBox.Show(Err.Description)
MsgBox("資料發生錯誤,請聯繫管理員")
Exit Sub
End Try
End Sub
為什麼會提示參數datatable的值為NULL。
再不出原因請幫我看看以上代碼是那裡錯了謝謝