在此网站上添加SqlConnection
部分有人建议,但仍然会出现异常
当标识插入为OFF时,无法为标识列插入显式值
on dv.SubmitChanges();
复合主键由stid
和bookid
组成。
另请告诉我如何在不连接文本框的值的情况下进行此查询,例如bname.Text
using (SqlConnection conn = new SqlConnection(cs))
{
conn.Open();
using (DataClasses1DataContext dv = new DataClasses1DataContext())
{
var iq = (from b in dv.Books
where SqlMethods.Like(b.name, "%" + bname.Text + "%")
select b.Id).FirstOrDefault();
IssueInfo info = new IssueInfo()
{
stid = Convert.ToInt32(rollno.Text),
due_date = Convert.ToDateTime(dateTimePicker1.Text),
bookid = Convert.ToInt32(iq)
};
dv.ExecuteCommand("SET IDENTITY_INSERT IssueInfo ON");
dv.IssueInfos.InsertOnSubmit(info);
dv.SubmitChanges();
dv.ExecuteCommand("SET IDENTITY_INSERT IssueInfo OFF");
}
}