读书人

添加数据时报错,该怎么处理

发布时间: 2011-12-29 22:09:38 作者: rapoo

添加数据时报错
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();

}
请高手帮忙看看有什么错误

[解决办法]
values前后加空格试试!

读书人网 >C#

热点推荐