首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2011-12-29 
添加数据时报错try{connnewSqlConnection( DataSourcecpt-16InitialCatalogclientUserIDsa )conn

添加数据时报错
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前后加空格试试!

热点排行