SqlCommand comm = new SqlCommand( "insert into student (studentID,Name,age)"+"values('"+TextBox1 .Text+ "''"+TextBox2 .Text +"''"+TextBox4 .Text+"')" ,connection );
是不是这样,,请各位高人指点一下

解决方案 »

  1.   

    用我这个string cmdText = string.Format("insert into student (studentID,Name,age) 
    values('{0}','{1}',{2})", TextBox1.Text, TextBox2.Text,TextBox4.Text);最好还是使用parameter方式给sql语句中的参数赋值
      

  2.   

    SqlCommand comm = new SqlCommand( "insert into student (studentID,Name,age) values('"+TextBox1 .Text.replace("'","")+ "', "+TextBox2 .Text.replace("'","")+"','"+TextBox4 .Text.replace("'","")+"')" ,connection ); 
      

  3.   

    二楼的用的是占位符,也不是太好,最好用Parameter不然在这些TEXTBOX的TEXT内容里如果有特殊字符的话也会有问题的
    比如英文字符的逗号