qq_36749049 2017-03-16 08:23 采纳率: 0%
浏览 918

C#数据库连接问题,路过的懂的话帮忙看看

String constr = @"Data Source=***********;Initial Catalog=" + kuming + ";User ID=sa;Password=***************;MultipleActiveResultSets=true";
SqlConnection con = new SqlConnection(constr);

con.Open();
string sql = "select * from DH_HH where name='" + username + "' and mima='" + password + "'";
SqlCommand com = new SqlCommand(sql, con);
SqlDataReader reader = com.ExecuteReader();
if (reader.Read())
{
string SQL = @"update DH_HH set mima='" + passnew + "' where name='" + username + "'";
SqlCommand coms = new SqlCommand(SQL,con);
if (coms.ExecuteNonQuery() == 1)
xiugai = "true";
}
reader.Close();//关闭执行
con.Close();//关闭数据库连接//

                            false'System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is closed. at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader() at WebService1.Service1.yanzheng(String json) in c:\Users\Administrator\Desktop\android\C#webservice\WebServiceHYWT\WebService1\Service1.asmx.cs:line 168'


                                                            第一个if语句为168行
  • 写回答

1条回答 默认 最新

  • jalen_zh 博客专家认证 2017-03-17 02:18
    关注

    建议你看下我的博客有篇文章专门讲了这个:http://blog.csdn.net/zhang_guyuan/article/details/53141482

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog