日期:2014-05-18  浏览次数:20498 次

向数据库添加数据时发生的错误
protected   void   Button1_Click1(object   sender,   EventArgs   e)
        {
string   strsql   =   "insert   into   jobs   values( ' "   +   TextBox1.Text   +   " ', ' "   +   TextBox2.Text   +   " ', ' "   +   TextBox3.Text   +   " ', ' "   +   TextBox4.Text   +   " ') ";
ExcuteSql(strsql);
         

        }
        protected   void   ExcuteSql(string   strsql)
        {
                SqlConnection   con   =   new   SqlConnection( "Data   Source=.;Initial   Catalog=pubs;User   ID=sa;Password=wwwtqbbacom ");
                con.Open();
                SqlCommand   com   =   new   SqlCommand(strsql,   con);
                com.ExecuteNonQuery();
                con.Close();

        }
能够生成页面.按BUTTON按钮后就出现
仅当使用了列的列表,并且   IDENTITY_INSERT   为   ON   时,才能在表   'jobs '   中为标识列指定显式值。


------解决方案--------------------
仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'jobs ' 中为标识列指定显式值。
===================
很明显,你对标识列插值了..估计你那个TextBox1.Text是不需要的
------解决方案--------------------
不了解,是不是你 给标志列赋值了
------解决方案--------------------
insert into jobs(对应的字段) values
------解决方案--------------------
比较大的可能性

string strsql = "insert into jobs values( ' " + TextBox1.Text + " ', ' " + TextBox2.Text + " ', ' " + TextBox3.Text + " ', ' " + TextBox4.Text + " ') ";
========================================================
string strsql = "insert into jobs values( ' " + TextBox2.Text + " ', ' " + TextBox3.Text + " ', ' " + TextBox4.Text + " ') ";