try
            {   
               conn = new SqlConnection("Data Source=cpt-16;Initial Catalog=client;User ID=sa");
                conn.Open();
                
                if (conn.State.ToString ()== "Close")
                {
                    conn.Open();
                }
                SqlCommand cmd = new SqlCommand("Insert into worker_info(workername,workersex,ptime,gtime)values('" + textBox1.Text + "' , '" + comboBox1.Text + "' ,  '" + textBox2.Text + "' ,  '" + textBox3.Text + "')", conn);
               // cmd.CommandText = "Insert into worker_info(workername,workersex,ptime,gtime)values('" + textBox1.Text + "','" + comboBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "'))";
                cmd.ExecuteNonQuery();            }
请高手帮忙看看有什么错误

解决方案 »

  1.   

    去掉最上面的values  不符合于法  ok
      

  2.   

    添加数据时报错  报错报的是什么错?是不是SQL语句有问题,把Insert into worker_info(workername,workersex,ptime,gtime)values('" + textBox1.Text + "' , '" + comboBox1.Text + "' ,  '" + textBox2.Text + "' ,  '" + textBox3.Text + "')放到查询分析器里试试,把textBox1.Text 换成具体的值,看可以执行吗?可以的话那SQL应该没问题!