| 发表于:2007-05-14 19:41:29 楼主 |
protected void button1_click(object sender, eventargs e) { string strconnection = system.configuration.configurationsettings.appsettings[ "strconnection "]; string strcmd= "select count(*) from userinfo where name = ' "+ textbox1.text + " ' and password = ' "+ textbox2.text + " ' "; sqlconnection myconnection = new sqlconnection(); myconnection.connectionstring = strconnection; sqlcommand mycommand=new sqlcommand(strcmd,myconnection); mycommand.connection.open(); int flag=(int)mycommand.EXECutescalar(); mycommand.connection.close(); myconnection.close(); if (flag> 0) { session[ "username "]=textbox1.text; response.redirect( "main.aspx "); } else { label1.text= "对不起!请输入正确的用户名和密码 "; textbox2.text= " "; } } 异常详细信息: system.invalidoperationexception: connectionstring 属性尚未初始化。 源错误: 行 21: 行 22: sqlcommand mycommand=new sqlcommand(strcmd,myconnection); 行 23: mycommand.connection.open(); 行 24: 行 25: int flag=(int)mycommand.EXECutescalar(); 源文件: c:\inetpub\wwwroot\default.aspx.cs 行: 23 要怎么修改? |
|
|
|
|