读书人

数据库的插入总是出错!解决方案

发布时间: 2012-03-20 14:01:10 作者: rapoo

数据库的插入总是出错!

SqlConnection sqlConnection1 =
new SqlConnection( "Data Source=YJY3;Initial Catalog=dflicapp;Integrated Security=True ");

try
{
SqlCommand cmd = new SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText =
"update dfapp2007 " +
" set shgsrs = ' " + shgsrs.Text + " ' " +
" shqsl = ' " + shqsl.Text + " ' " ;// 怎么总是在这里报错!

cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
result2.Visible = true;
}
catch (SqlException ex)
{
Response.Write(ex.Number);
Response.Write(ex.Message);
Response.Write(ex.StackTrace);
}
finally
{
sqlConnection1.Close();
}

[解决办法]
", shqsl = ' " + shqsl.Text + " ' " ;// 怎么总是在这里报错!
[解决办法]
//
cmd.CommandText =
"update dfapp2007 " +
" set shgsrs = ' " + shgsrs.Text + " ' " +
" shqsl = ' " + shqsl.Text + " ' " ;// 怎么总是在这里报错!


Console.WriteLine(cmd.CommandText); //先输出到查询分析器里测试看看

//------据我估计是少了“,”
" set shgsrs = ' " + shgsrs.Text + " ', " +
// ~~~
[解决办法]
" ,shqsl = ' " + shqsl.Text + " ' " ;// 怎么总是在这里报错!
前面加,

读书人网 >C#

热点推荐