con.Open();
  string str = "insert into stu(stu_name,stu_psd) values(" + textBox1.Text + "," + textBox2.Text + ")";
  SqlCommand cmd = new SqlCommand(str, con);
  cmd.ExecuteNonQuery();
//连接语句省略不写了,连接是成功的
我就是VS里拖了2个Textbox控件
一个button控件,然后点击的时候出现
在此上下文中不允许使用名称 "dai"。有效表达式包括常量、常量表达式和变量(在某些上下文中)。不允许使用列名。

解决方案 »

  1.   

    string str = "insert into stu(stu_name,stu_psd) values('" + textBox1.Text + "’,‘" + textBox2.Text + ")";’
      

  2.   

    应该如下:
    string str = "insert into stu(stu_name,stu_psd) values('" + textBox1.Text + "','" + textBox2.Text + "')";
      

  3.   

    string str ="insert into stu (stu_name,stu_pad) value ('"+textBox.Text.ToString()+"','"+textBox2.Text.ToSting()+"')";
      

  4.   

    con.Open();
    string str = "insert into stu(stu_name,stu_psd) values('" + textBox1.Text + "','" + textBox2.Text + "')";
    SqlCommand cmd = new SqlCommand(str, con);
    cmd.ExecuteNonQuery();
    con.Close();//用完就关闭
      

  5.   

    string str = "insert into stu(stu_name,stu_psd) values('" + textBox1.Text + "','" + textBox2.Text + "')";
    或String.Foramt("insert into stu(stu_name,stu_psd) values('{0}','{1}')",textBox1.Text ,textBox2.Text )