从 ms 访问中获取表数
本文关键字:获取 ms 访问 | 更新日期: 2023-09-27 17:55:29
我正在使用C#为cachier开发一个程序。对数据库使用 ms 访问的程序。不知何故,数据库没有输入到表中。我的问题在哪里?这是代码:
private void buttonCloseCart_Click(Object sender, EventArgs e) { 连接。连接字符串 = 连接字符串; 连接。打开(); OleDbCommand cmd1 = new OleDbCommand("INSERT INTO ReceiptItem (ItemID, Quantity, UnitPrice) VALUES (@itemID, @temp_item_quantity, @temp_item_price)", connect); CMD1.Parameters.Add("@temp_item", OleDbType.Char, 20); CMD1.Parameters.Add("@temp_item_quantity", OleDbType.Integer, 20); CMD1.Parameters.Add("@temp_item_price", OleDbType.Double, 20); CMD1.Parameters.Add("@cart_sum", OleDbType.Double, 20); CMD1.Parameters.Add("@itemID", OleDbType.Integer, 20);
for (int i = 0; i < baught_items.Count; i++)
{
/*Set temporary reference to the objects located on the List*/
string temp_item = baught_items[i].ToString();
int temp_item_quantity = baught_items_quantity[i];
double temp_item_price = baught_items_price[i];
double temp_total_item_price = total_items_price[i];
/*Set the connection to the CachierPro DataBase*/
OleDbConnection myconnection = new OleDbConnection(connect.ConnectionString);
myconnection.Open();
//OleDbConnection myconnection1 = new OleDbConnection(connect.ConnectionString);
//myconnection1.Open();
/*********************************************/
/*This Action get the Item Name directly from the database according to the item name in the cart*/
//OleDbConnection dataConnection = new OleDbConnection();
//dataConnection.ConnectionString = connString;
//dataConnection.Open();
//OleDbConnection oledbConn = new OleDbConnection(connString);
//oledbConn.Open();
//OleDbCommand myCommand1 = new OleDbCommand();
//myCommand1.Connection = myconnection1;
//myCommand1.Connection.Close();
OleDbCommand cmd = new OleDbCommand("SELECT [ItemID] FROM ItemsList WHERE [ItemName] = " + "'"+temp_item +"'" , connect);
OleDbDataReader dataReader = cmd.ExecuteReader();
if (dataReader.Read()) { }
int itemID = dataReader.GetInt32(0);
/********************************************/
/*Initialize the Command ment for the Query*/
OleDbCommand myCommand = new OleDbCommand();
myCommand.Connection = myconnection;
//myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
//dataConnection.Close();
//oledbConn.Close();
myconnection.Close();
dataReader.Close();
/*Enter the first query*/
if (connect.State == ConnectionState.Open)
{
try
{ int addedCount = cmd.ExecuteNonQuery(); }
catch (Exception expe)
{ MessageBox.Show(expe.Message); connect.Close(); }
}
else
{
MessageBox.Show("Connection Failed");
}
}
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = new OleDbCommand("SELECT * FROM ReceiptItem", connect);
DataTable dt = new DataTable();
da.Fill(dt);
textBoxCurrentCartSumTXT.Clear();
textBoxPricePerOneTXT.Clear();
textBoxQuantityTXT.Clear();
textBoxSumForCurrentItemTXT.Clear();
connect.Close();
}
项目
项标识
项目名称
商品价格
食谱
往复式ID
收款发票编号
回程日期时间
回馈物品
往复式ID
项标识
数量
单价