日期:2014-05-17 浏览次数:22933 次
string sqlstr = "insert into tb_BookInfo (BookName,BookIntroduce,BookPrice,BookIsNew) values(@BookName,@BookIntroduce,@BookPrice,@BookIsNew)";
SqlCommand mycom = new SqlCommand(sqlstr, con);
//添加参数
mycom.Parameters.Add(new SqlParameter("@BookName", SqlDbType.VarChar,50));
mycom.Parameters.Add(new SqlParameter("@BookIntroduce", SqlDbType.VarChar,50));
mycom.Parameters.Add(new SqlParameter("@BookPrice", SqlDbType.Money,8));
mycom.Parameters.Add(new SqlParameter("@BookIsNew", SqlDbType.Char,10));
//给参数赋值
mycom.Parameters["@BookName"].Value = TextBox1.Text;
mycom.Parameters["@BookIntroduce"].Value = TextBox2.Text;
mycom.Parameters["@BookPrice"].Value = Convert.ToDecimal(TextBox3.Text);
mycom.Parameters["@BookIsNew"].Value = DropDownList1.SelectedValue.ToString();
//执行添加语句
mycom.ExecuteNonQuery();
con.Close();