Dim result(10)‘有n列定义n-1个,从0开始的
dim STRstr as String=DataGridView1.Item(2, DataGridView1.CurrentCell.RowIndex).Value.ToString.Trim'将关键值字段值给全局变量,这里我将产品编号做为关键字段
dim i as integer
for i=0 to n-1 'n是多少列
result(i) = DataGridView1.Item(i, DataGridView1.CurrentCell.RowIndex).Value.ToString.Trim
next
Dim updatastr As String = "update 卓艺标准工时 set " 'set 后留一空格
if result(0)<>"" then
updatastr=updatastr & "序号='" & result(0) & "',"
else
updatastr=updatastr & "序号=''," '如果不设此值,更新时会出错
endif
if result(1)<>"" then
updatastr=updatastr & "产品编号='" & result(1) & "',"
else
updatastr=updatastr & "产品编号='',"
endif
...........................最后一项后面不要加逗号
updataStr = updataStr & " where 产品编号='" & STRstr "'" ’where 前留一空格
cn.Open()
Dim da As New oledbommand(updataStr, cn)
= CommandType.Text
da.ExecuteNonQuery()
此方法比较笨,应该有更好的办法,不过能实现你要的结果。。。。