这是方法。 public int InsertGoodsInTable(long stockinid,DateTime stickindate,string chargename,string goodsname,string goodsunit,int goodscount,string customersname,decimal fieightcount,decimal collectionmoney,DateTime systemdate)
{
//try
//{
int return_;
con_str = GlobarVariables.DBConnectstring;
OleDbConnection igit_con = new OleDbConnection(con_str);
igit_con.Open();
string sql = "INSERT INTO GoodsInTable (StockInId,StockInDate,ChargeName,GoodsName,GoodsUnit,GoodsCount,CustomersName,FreightCount,CollectionMoney,Systemdate) VALUES (" + stockinid + "," + stickindate + ",'" + chargename + "','" + goodsname + "','" + goodsunit + "'," + goodscount + ",'" + customersname + "'," + fieightcount + "," + collectionmoney + "," + systemdate + ")";
OleDbCommand igit_cmd = new OleDbCommand(sql, igit_con);
return_ = igit_cmd.ExecuteNonQuery();
igit_con.Close();
return return_;
//}
//catch (Exception e)
//{
// //写日志。
// TextOpera to = new TextOpera();
// to.WhiteWorklog(DateTime.Now.ToString() + "\r\n" + e.ToString());
// return -1;
//}
}这是后台代码 private void button1_Click(object sender, EventArgs e)
{
//MessageBox.Show(.ToString());
AccessDBOpera b1 = new AccessDBOpera();
int a = b1.InsertGoodsInTable(Convert.ToInt32(textBox3.Text), DateTime.Now, textBox4.Text, comboBox2.Text, comboBox3.Text, Convert.ToInt16(comboBox4.Text), comboBox1.Text, Convert.ToDecimal(textBox1.Text), Convert.ToDecimal(textBox2.Text), DateTime.Now);
MessageBox.Show(a.ToString());
}
{
//try
//{
int return_;
con_str = GlobarVariables.DBConnectstring;
OleDbConnection igit_con = new OleDbConnection(con_str);
igit_con.Open();
string sql = "INSERT INTO GoodsInTable (StockInId,StockInDate,ChargeName,GoodsName,GoodsUnit,GoodsCount,CustomersName,FreightCount,CollectionMoney,Systemdate) VALUES (" + stockinid + "," + stickindate + ",'" + chargename + "','" + goodsname + "','" + goodsunit + "'," + goodscount + ",'" + customersname + "'," + fieightcount + "," + collectionmoney + "," + systemdate + ")";
OleDbCommand igit_cmd = new OleDbCommand(sql, igit_con);
return_ = igit_cmd.ExecuteNonQuery();
igit_con.Close();
return return_;
//}
//catch (Exception e)
//{
// //写日志。
// TextOpera to = new TextOpera();
// to.WhiteWorklog(DateTime.Now.ToString() + "\r\n" + e.ToString());
// return -1;
//}
}这是后台代码 private void button1_Click(object sender, EventArgs e)
{
//MessageBox.Show(.ToString());
AccessDBOpera b1 = new AccessDBOpera();
int a = b1.InsertGoodsInTable(Convert.ToInt32(textBox3.Text), DateTime.Now, textBox4.Text, comboBox2.Text, comboBox3.Text, Convert.ToInt16(comboBox4.Text), comboBox1.Text, Convert.ToDecimal(textBox1.Text), Convert.ToDecimal(textBox2.Text), DateTime.Now);
MessageBox.Show(a.ToString());
}
string sql = "INSERT INTO GoodsInTable (StockInId,StockInDate,ChargeName,GoodsName,GoodsUnit,GoodsCount,CustomersName,FreightCount,CollectionMoney,Systemdate) VALUES (" + stockinid + ",'" + stickindate + "','" + chargename + "','" + goodsname + "','" + goodsunit + "'," + goodscount + ",'" + customersname + "'," + fieightcount + "," + collectionmoney + "," + systemdate + ")";其它地方再检查检查,看哪里还需要单引号的,记得加上……