无法将类型“System.Data.SqlClient.SqlConnection”隐式转换为“string
以下为实现登录功能的代码,请问错误在哪里?protectedvoidButton2_Click(objectsender,EventArgse){stringconn=n...
以下为实现登录功能的代码,请问错误在哪里? protected void Button2_Click(object sender, EventArgs e) { string conn = new SqlConnection("Data Source=(local)\\SQLEXPRESS;Integrated Security=true;database=bj1"); string strCmd="select count(*) from dbo.Table_1 where(username like '"+TextBox1.Text+"'and code like '"+TextBox2.Text+"')"; SqlConnection myConnection=new SqlConnection(); myConnection.ConnectionString=conn; SqlCommand myCommand=new SqlCommand(strCmd,myConnection); myCommand.Connection.Open(); //检索出的用户数 int flag=(int)myCommand.ExecuteScalar(); myCommand.Connection.Close(); myConnection.Close(); Response.Write("<script>alert('登陆成功')</script>"); } 请问错在哪里?谢谢
展开
3个回答
推荐于2018-04-13
展开全部
string conn = new SqlConnection("Data Source=(local)\\SQLEXPRESS;Integrated Security=true;database=bj1"); 你new的是SqlConnection类型,不能用string接受,改为SqlConnection conn = new SqlConnection("Data Source=(local)\\SQLEXPRESS;Integrated Security=true;database=bj1");
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-04
展开全部
string conn = new SqlConnection("Data Source=(local)\\SQLEXPRESS;问题出现在这里。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-04
展开全部
SqlConnection myConnection=new SqlConnection ();
myConnection.ConnectionString = "Data Source=ZWZX008\\SQL2005; Initial Catalog=northwind;User ID=Sa;Password=123456";
myConnection.Open();
SqlCommand myCommand = new SqlCommand(myConnection);
myCommand.CommandText = "Select * from Customers";
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
myConnection.ConnectionString = "Data Source=ZWZX008\\SQL2005; Initial Catalog=northwind;User ID=Sa;Password=123456";
myConnection.Open();
SqlCommand myCommand = new SqlCommand(myConnection);
myCommand.CommandText = "Select * from Customers";
SqlDataReader myReader;
myReader = myCommand.ExecuteReader();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询