我试图在sql栏下获取数据" Price"当我从下拉列表中选择并输入一个数量时将使用其ItemName(然后将其作为一个sql行selectitemfromdropdown插入ItemName列+数量列数量+我尝试从另一个表中获取的价格)。
我使用了数据集表适配器" datPrice"并将其存储在数据表" tblPrice"。该行
发生错误int price = Convert.ToInt32(tblPrice.Rows[0]["Price"].ToString());
因为它说
输入字符串的格式不正确
如何解决错误?
protected void btnSave_Click(object sender, EventArgs e)
{
DataSetTableAdapters.RawMaterialMFTableAdapter datItemName = new DataSetTableAdapters.RawMaterialMFTableAdapter();
DataTable tblItemID = new DataTable();
tblItemID = datItemName.GetDataByItemName(drpItemName.Text);
int itemID = Convert.ToInt32(tblItemID.Rows[0]["ItemID"].ToString());
DataSetTableAdapters.RawMaterialMFTableAdapter datPrice = new DataSetTableAdapters.RawMaterialMFTableAdapter();
DataTable tblPrice = new DataTable();
tblPrice = datPrice.GetDataByPrice(drpItemName.Text);
int price = Convert.ToInt32(tblPrice.Rows[0]["Price"].ToString()); // Error on this line
int total = price * Convert.ToInt32(txtQuantity.Text.ToString());
DataSetTableAdapters.QRawMaterialTableAdapter datData = new DataSetTableAdapters.QRawMaterialTableAdapter();
datData.InsertQueryQRM(itemID, Convert.ToInt32(txtQuantity.Text.ToString()), price, total);
}
答案 0 :(得分:0)
int price = int.Parse(tblPrice.Rows[0]["Price"].ToString());
试一试。