将ID设为表示自增加,为什么插入数据时出错:当 IDENTITY_INSERT 设置为 OFF 时,不能向表 'bbs_Article' 中的标识列插入显式值。
应该如何修改?在SQL中,还是代码中?

解决方案 »

  1.   

    代码:
    private void btnSubmit_Click(object sender, System.EventArgs e)
    {
    string articleTitle = this.txtTitle.Text;
    string articleContent=this.txtContent.Text;
    SqlConnection con = DB.createCon();
    con.Open();
    SqlCommand cmd1=new SqlCommand ("select articleID  from bbs_Article order by articleID DESC",con);
    int rootID=Convert.ToInt32 (cmd1.ExecuteScalar ())+1;
    SqlCommand cmd = new SqlCommand ("insert into bbs_Article(articleTitle,articleContent,rootID,articleBoard) values('"+@articleTitle+"','"+@articleContent+"',"+@rootID+",1)  ",con); cmd.ExecuteNonQuery();
    con.Close();
    Response.Redirect ("showLuntan.aspx"); }
    请帮忙看一下,谢谢