在我的表单中,当我修改数据时出现错误,因为 “没有为命令对象设置命令文本”
我正在使用 oledb 连接
关注我的代码
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
sql = "select * from Employee"
conn = New OleDbConnection(s)
adapt = New OleDbDataAdapter(sql, conn)
ds = New DataSet
usql = "Update Employee set enp_name=?, emp_addr=?, DOB=?, DOJ=?, emp_mob=?, emp_mail=? where ID=?"
ucmd = New OleDbCommand(isql, conn)
Dim date1 As Date
date1 = DateTimePicker1.Value
p = ucmd.Parameters.Add("@emp_name", OleDbType.Char)
p.SourceColumn = "emp_name"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("@emp_addr", OleDbType.Char)
p.SourceColumn = "emp_addr"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("@DOB", OleDbType.DBDate)
p.SourceColumn = "DOB"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("@DOJ", OleDbType.DBDate)
p.SourceColumn = "DOJ"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("@emp_mob", OleDbType.Integer)
p.SourceColumn = "emp_mob"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("@emp_mail", OleDbType.Char)
p.SourceColumn = "emp_mail"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("@ID", OleDbType.Integer)
p.SourceColumn = "ID"
p.SourceVersion = DataRowVersion.Current
adapt.UpdateCommand = ucmd
conn.Open()
If conn.State = ConnectionState.Open Then
adapt.MissingSchemaAction = MissingSchemaAction.AddWithKey
adapt.Fill(ds, "ABC")
'conn.Close()
End If
tables = ds.Tables
table = tables("ABC")
rows = table.Rows
cols = table.Columns
row = rows.Find(TextBox1.Text)
row.BeginEdit()
row("ID") = TextBox1.Text
row("emp_name") = TextBox2.Text
row("emp_addr") = TextBox3.Text
row("DOB") = DateTimePicker1.Text
row("DOJ") = DateTimePicker2.Text
row("emp_mob") = TextBox4.Text
row("emp_mail") = TextBox5.Text
row.EndEdit()
'conn.Open()
adapt.Update(ds, "ABC")** Getting error on this line
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
但我没有找到我要去的地方....请帮助我