con.Open()
sql = "select * from Rates where From ='" + ComboBox1.Text + "'"
sqlcmd = New OleDb.OleDbCommand(sql, con)
reader = sqlcmd.ExecuteReader
While reader.Read
TxtTo.Text = reader.Item("To")
TxtRatePerTon.Text = reader.Item("RatesPerTon")
TxtRatePerTrip.Text = reader.Item("RatesPerTrip")
End While
reader.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Dim cb As New OleDb.OleDbCommandBuilder(da)
ds.Tables("Transport2003").Rows(inc).Item(1) = TxtDate.Text
ds.Tables("Transport2003").Rows(inc).Item(2) = TxtFreightSlipNo.Text
ds.Tables("Transport2003").Rows(inc).Item(3) = ComboBox1.SelectedValue
ds.Tables("Transport2003").Rows(inc).Item(4) = TxtTo.Text
ds.Tables("Transport2003").Rows(inc).Item(5) = TxtRatePerTon.Text
ds.Tables("Transport2003").Rows(inc).Item(6) = TxtRatePerTrip.Text
ds.Tables("Transport2003").Rows(inc).Item(7) = ComboBox2.SelectedValue.ToString
ds.Tables("Transport2003").Rows(inc).Item(8) = ComboBox3.SelectedValue.ToString
ds.Tables("Transport2003").Rows(inc).Item(9) = TxtTon.Text
ds.Tables("Transport2003").Rows(inc).Item(10) = ComboBox4.SelectedValue.ToString
ds.Tables("Transport2003").Rows(inc).Item(11) = TxtExtra.Text
ds.Tables("Transport2003").Rows(inc).Item(12) = TxtTrips.Text
ds.Tables("Transport2003").Rows(inc).Item(13) = TxtActualWeight.Text
ds.Tables("Transport2003").Rows(inc).Item(14) = TxtBillWeight.Text
ds.Tables("Transport2003").Rows(inc).Item(15) = TxtAmount.Text
da.Update(ds, "Transport2003")
答案 0 :(得分:1)
如果没有更多信息,我猜你的select
声明无效。 FROM
是一个关键字(无论如何都在SQL Server中),语句select * from Rates where From ='
无效。您将收到一条消息说明
消息156,级别15,状态1,行1关键字附近的语法不正确 '从'。
要解决此问题,请将From放在括号中,即select * from Rates where [From] ='
作为一般规则,在命名任何数据库对象时应避免使用键名;它让生活更轻松。