我用的也是05,只是修改了一下数据库连接字符串和查询语句,没有报错,帮忙看看啊:
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
Dim da As New SqlDataAdapter
Dim cb As New SqlCommandBuilder
Dim ds As New DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New SqlConnection("Data Source=.;Initial Catalog=dps003b;User ID=sa;password=sa")
Try
Dim com As New SqlCommand("SELECT ManNo, ManName, sex, ZW, remark,isused FROM StoreMan", con)
da = New SqlDataAdapter(com)
da.SelectCommand = com
da.UpdateCommand = com '加了这句这句,没有的话会报错
cb = New SqlCommandBuilder(da)
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
da.Update(ds.Tables(0).GetChanges())
ds.Tables(0).AcceptChanges()
ds.Tables.Clear() '加了这一句,重新绑定前清空ds
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Me.Button1.Focus()
Try
'ds.Tables(0).Rows(DataGridView1.CurrentRow.Index).Delete()
da.Update(ds.Tables(0).GetChanges())
ds.Tables(0).AcceptChanges()
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
End Class
[此贴子已经被作者于2006-9-14 12:24:51编辑过]