以前都是用SQL语句做的,第一次用存储过程,大家帮个忙..谢啦./
我就是想调用存储过程往数据库中添加记录..代码如下,但都是提示连接数据库出错.哪里出了问题呢???
string myStr = "Data Source=服务器;Initial Catalog=数据库;Integrated Security=SSPI";
SqlConnection conn = new SqlConnection(myStr);
try
{
conn.Open();
SqlCommand myCom = new SqlCommand("InsertBuyIn",conn);
myCom.CommandType = CommandType.StoredProcedure;
myCom.Parameters.Add("@Item_code",SqlDbType.VarChar,50);
myCom.Parameters.Add("@Item_type", SqlDbType.VarChar, 50);
myCom.Parameters.Add("@Item_name", SqlDbType.VarChar, 50);
myCom.Parameters.Add("@Buy_quantity", SqlDbType.Int, 4);
myCom.Parameters.Add("@Buy_price", SqlDbType.Decimal, 9);
myCom.Parameters.Add("@Buyer", SqlDbType.VarChar, 50);
myCom.Parameters.Add("@Buy_time", SqlDbType.DateTime, 8);
myCom.Parameters.Add("@Down_limited", SqlDbType.Int, 4);
myCom.Parameters.Add("@Remark", SqlDbType.VarChar,60);
myCom.Parameters["@Item_code"].Value = textBox1.Text;
myCom.Parameters["@Item_type"].Value = textBox2.Text;
myCom.Parameters["@Item_name"].Value = textBox3.Text;
myCom.Parameters["@Buy_quantity"].Value = textBox4.Text;
myCom.Parameters["@Buy_price"].Value = textBox5.Text;
myCom.Parameters["@Buyer"].Value = textBox6.Text;
myCom.Parameters["@Buy_time"].Value = comboBox1.Text;
myCom.Parameters["@Down_limited"].Value = textBox7.Text;
myCom.Parameters["@Remark"].Value = textBox8.Text;
myCom.ExecuteNonQuery();
}
catch
{
MessageBox.Show("连接数据库出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
this.Cursor = Cursors.Default;
return;
}
conn.Close();