为何我的插入就是不行呢???
高手请指教一下,当我点击“添加”的时候,就是不行,麻烦能否给指点一下?谢谢。public static bool insertOperate(oil y)
{
try
{
SqlConnection con=oilOperate.createCon();
con.Open();
// SqlCommand cmd=new SqlCommand("insert into price values(y.DateTime,y.Categories,y.Products,y.TodayPrices,y.PreviousDay,y.Remarks,y.Units,y.messagePerson,y.messageUnit,y.visiable)",con);
SqlCommand cmd=new SqlCommand("insert into Price values(@DateTime,@Categories,@Products,@TodayPrices,@PreviousDay,@Remarks,@Units,@messagePerson,@messageUnit,@visiable)",con);
SqlParameter para=new SqlParameter("@DateTime",SqlDbType.SmallDateTime,4);
para.Value=y.DateTime;
cmd.Parameters.Add(para);
para=new SqlParameter("@Categories",SqlDbType.VarChar,20);
para.Value=y.Categories;
cmd.Parameters.Add(para);
para=new SqlParameter("@Products",SqlDbType.VarChar,20);
para.Value=y.Products;
cmd.Parameters.Add(para);
para=new SqlParameter("@TodayPrices",SqlDbType.VarChar,20);
para.Value=y.TodayPrices;
cmd.Parameters.Add(para);
para=new SqlParameter("@PreviousDay",SqlDbType.VarChar,20);
para.Value=y.PreviousDay;
cmd.Parameters.Add(para);
para=new SqlParameter("@Remarks",SqlDbType.VarChar,50);
para.Value=y.Remarks;
cmd.Parameters.Add(para);
para=new SqlParameter("@Units",SqlDbType.VarChar,20);
para.Value=y.Units;
cmd.Parameters.Add(para);
para=new SqlParameter("@messagePerson",SqlDbType.VarChar,50);
para.Value=y.messagePerson;
cmd.Parameters.Add(para);
para=new SqlParameter("@messateUnit",SqlDbType.VarChar,50);
para.Value=y.messageUnit;
cmd.Parameters.Add(para);
para=new SqlParameter("@visiable",SqlDbType.VarChar,10);
para.Value=y.visiable;
cmd.Parameters.Add(para);
cmd.ExecuteNonQuery();
return true;
}
catch(Exception e)
{
return false;
}
}