namespace DAL
{
public class bookDAL
{
public int addBooks(books objbooks)
{
StringBuilder sb = new StringBuilder();
sb.Append("insert into books(书号,书名,作者,出版社,出版日期) values ");
sb.Append(" (@bookNum,@title,@author,@publish,@time)");
SqlParameter[] param = { SQLHelper.GetParameter("@bookNum",SqlDbType.NVarChar,50,"书号",objbooks.BookNum),
SQLHelper.GetParameter("@title",SqlDbType.NVarChar,50,"title",objbooks.Title),
SQLHelper.GetParameter("@author",SqlDbType.NVarChar,50,"作者",objbooks.Author),
SQLHelper.GetParameter("@publish",SqlDbType.NVarChar,50,"出版社",objbooks.PublishBook),
SQLHelper.GetParameter("@time",SqlDbType.NVarChar,50,"出版日期",objbooks.Time)
};
return SQLHelper.ExecuteSql(sb.ToString(), param);
}
把@理解成啊占位符就行,("@title",SqlDbType.NVarChar,50,"title",objbooks.Title) 指定参数类型、长度、数据库对应字段、值,看方法注解啊!
拼sql语句插入数据
("@title",SqlDbType.NVarChar,50,"title",objbooks.Title)这是什么意思,还有@title是什么写法@,谢谢你
@小感伤3: 楼下说得对,@title。sql里面表示这是一个参数。
没太明白,sqlserver的基础知识欠缺?
我已经解决了,谢谢大家办网