As the error states: Must declare the scalar variable "@UserType"
In other words, the SQL command has a parameter for @UserType
, but there are no parameters declared in the parameters collection.
SqlCommand cmd = new SqlCommand(
"select * from dbo.UserInfo where Login =@Login and UserType=@UserType and Password=@Password and UserType=@UserType", con);
cmd.Parameters.AddWithValue("@Login", txtUserName.Text);
cmd.Parameters.AddWithValue("@Password", txtPWD.Text+".123");
Add another parameter for the @UserType
parameter:
cmd.Parameters.AddWithValue("@UserType", "User Type");
Also, the SQL contains a duplicate reference to for @UserType
:
select * from dbo.UserInfo
where Login=@Login
and UserType=@UserType
and Password=@Password
and UserType=@UserType
Should probably be:
select * from dbo.UserInfo
where Login=@Login
and Password=@Password
and UserType=@UserType
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…