string str = "server='(local)';database='book_manage';uid='sa';pwd='123'"; //连接数据库
            SqlConnection con = new SqlConnection(str); //创建连接
            con.Open(); //打开连接
            string strsql =
            "insert into StoreIn(bookid,bookname,editor,booknum,publishname,bookprice,pulicationdate,booktype) values ('" + bookid.Text + "' ,'" + bookname.Text + "','" + editor.Text + "','" + booknum.Text + "' ,'" + publishname.Text + "','" + bookprice.Text + "','" + pulicationdate.Text + "' ,'" + booktype.Text + "')";
  
            SqlCommand sqlcom = new SqlCommand(strsql, con);            sqlcom.ExecuteNonQuery();            con.Close();

解决方案 »

  1.   

    数据库表中的booknum 是int型 bookprice是float型  其余全是nchar型
      

  2.   

    string str = "server='(local)';database='book_manage';uid='sa';pwd='123'"; 改成:string str = "server=localhost;database=book_manage;uid=sa;pwd=123"; 
      

  3.   

    数据路连接字符串错了,改正后,调试一下sql语句对不?
      

  4.   

    string str = "server=.;database=book_manage;uid=sa;pwd=123"; //连接数据库
      

  5.   

    你的booknum以及bookprice两边不用加单引号,其余nchar型两边加单引号.
      

  6.   

    你在数据库里改数据库表中的booknum 是int型 bookprice是float型 其余全是nchar型  中的nchar为verchar类型
      

  7.   

    搞半天,不如,把生成的Sql 放到数据库里执行一次,一看就知道哪错了,
      

  8.   

    改为varchar型也是不可以  是不是语句出错了呢?
      

  9.   

    你的 pulicationdate是不是日期,是的话改为data类型
      

  10.   

    把插入语句放入sql中运行  出现下面的错误 怎么改还是如此  请问插入语句哪里错了呢消息 102,级别 15,状态 1,第 1 行
    '(' 附近有语法错误。
      

  11.   

    有datetime型  改为datetime型了  不过datetime型是什么样的格式呢  在输入日期的textbox中怎么填写日期格式呢
      

  12.   


    string str = "server='(local)';database='book_manage';uid='sa';pwd='123'"; //连接数据库
       SqlConnection con = new SqlConnection(str); //创建连接
       con.Open(); //打开连接
       string strsql =
       "insert into StoreIn(bookid,bookname,editor,booknum,publishname,bookprice,pulicationdate,booktype) values ('" + bookid.Text + "' ,'" + bookname.Text + "','" + editor.Text + "'," + booknum.Text + " ,'" + publishname.Text + "'," + bookprice.Text + ",'" + pulicationdate.Text + "' ,'" + booktype.Text + "')";
        
      SqlCommand sqlcom = new SqlCommand(strsql, con);   sqlcom.ExecuteNonQuery();   con.Close();
    string str = "server='(local)';database='book_manage';uid='sa';pwd='123'"; //连接数据库
       SqlConnection con = new SqlConnection(str); //创建连接
       con.Open(); //打开连接
       string strsql =
       "insert into StoreIn(bookid,bookname,editor,booknum,publishname,bookprice,pulicationdate,booktype) values ('" + bookid.Text + "' ,'" + bookname.Text + "','" + editor.Text + "','" + booknum.Text + "' ,'" + publishname.Text + "','" + bookprice.Text + "','" + pulicationdate.Text + "' ,'" + booktype.Text + "')";
        
      SqlCommand sqlcom = new SqlCommand(strsql, con);   sqlcom.ExecuteNonQuery();   con.Close();
      

  13.   

    如何才能实现往数据库表中插入值  判断表中已有数据的ID与插入数据的的ID  如果相同就提示此ID已存在呢?