代码如下
private void button1_Click(object sender, EventArgs e)
        {            SqlConnection sqc = new SqlConnection();
            sqc.ConnectionString = "Data Source=localhost;Initial Catalog=ll;Integrated Security=SSPI";
            sqc.Open();
            SqlCommand comm = new SqlCommand("insert into cunkuanren(name,sfz,tel,adress,bz) values(" + textBox2.Text + "," + textBox3.Text + "," + textBox4.Text + "" + textBox5.Text + "," + textBox6.Text + ")", sqc);
            comm.ExecuteNonQuery();
            sqc.Close();        }        private void button3_Click_1(object sender, EventArgs e)
        {
            SqlConnection sqc = new SqlConnection();
            sqc.ConnectionString = "Data Source=localhost;Initial Catalog=ll;Integrated Security=SSPI";
            sqc.Open();
            SqlCommand comm = new SqlCommand("update cunkuanren set name='" + textBox2.Text.Trim() + "',sfz='" + textBox3.Text.Trim() + "', tel='" + textBox4.Text.Trim() + "',adress='" + textBox5.Text.Trim() + "',bz ='" + textBox6.Text.Trim() + "'", sqc);
            comm.ExecuteNonQuery();
            sqc.Close();
        }        private void button2_Click_1(object sender, EventArgs e)
        {
                        SqlConnection sqc = new SqlConnection();
            sqc.ConnectionString = "Data Source=localhost;Initial Catalog=ll;Integrated Security=SSPI";
            sqc.Open();
            SqlCommand comm = new SqlCommand("delete from cunkuanren where id='" + textBox1.Text.Trim() + "'", sqc);
            comm.ExecuteNonQuery();
            sqc.Close();
        }执行后提示 comm.ExecuteNonQuery();这句不对  哪里的问题啊  请高手帮忙

解决方案 »

  1.   

    这一句有问题:SqlCommand comm = new SqlCommand("insert into cunkuanren(name,sfz,tel,adress,bz) values(" + textBox2.Text + "," + textBox3.Text + "," + textBox4.Text + "" + textBox5.Text + "," + textBox6.Text + ")", sqc);根据字段的数据类型写sql语句,如果是文本型则需要加一对单引号,你没加。
      

  2.   

    数字类型的话就不用加'',如果是字符型的话就要 '"+textBox1.Text+"' 这种格式,如果是ACESS,这种错误很烦人;SQL的话即使是数字类型 ,加个'' 也是没关系的
      

  3.   

    还有我用CellClick事件写显示到textbox中为什么不行 代码是
                   DataGridViewRow ck;
                ck = this.dataGridView1.SelectedRows[0];
                textBox1.Text = ck.Cells[0].Value.ToString();
                textBox1.Enabled = false;
                textBox2.Text = ck.Cells[1].Value.ToString();
                textBox3.Text = ck.Cells[2].Value.ToString();
                textBox4.Text = ck.Cells[3].Value.ToString();
                textBox5.Text = ck.Cells[4].Value.ToString();
                textBox6.Text = ck.Cells[5].Value.ToString();