我不断收到此错误,因为该记录的 VendorID 为空。我已经看到这个问题已经被问过几次了,似乎我应该在它转换它并将它输入到 dbtable 之前检查是否为 null,但我不知道该怎么做。
public static PartOrder findPartOrder(string orderNo)
{
PartOrder aPartOrder = new PartOrder();
OleDbDataAdapter myAdapter = new OleDbDataAdapter();
if (aConnection.State == ConnectionState.Closed)
aConnection.Open();
OleDbCommand cmd = aConnection.CreateCommand();
OleDbDataReader dbReader = null;
cmd.CommandText = "SELECT * FROM PartOrder WHERE OrderNo = '" + orderNo + "'";
dbReader = cmd.ExecuteReader();
while (dbReader.Read())
{
aPartOrder.OrderNo = (string)dbReader.GetValue(0);
aPartOrder.Length = (string)dbReader.GetValue(1);
aPartOrder.Finish = (string)dbReader.GetValue(2);
aPartOrder.Cost = (string)dbReader.GetValue(3);
aPartOrder.PartDrawingNo = (string)dbReader.GetValue(4);
aPartOrder.VendorId = (string)dbReader.GetValue(5);
aPartOrder.ShopId = (string)dbReader.GetValue(6);
aPartOrder.Completed = (string)dbReader.GetValue(7);
}
dbReader.Close();
return aPartOrder;
}
再次,“aPartOrder.VendorId = (string)dbReader.GetValue(5);”这一行 收到错误,因为 VendorId 为空。