Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When i try to run this code if i enter the write details is shows me that the username or password is not correct which is what i want but the case is wen m entering the correct details it shows me this msg
Unable to cast object of type 'System.Int32' to type 'System.String'.
Here is my code

C#
string username = loginDetails.UserName;
           string pwd = loginDetails.Password;

           string s;
           s = WebConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
           SqlConnection con = new SqlConnection(s);
           con.Open();
           string sqlUserName;
           sqlUserName = "SELECT * FROM ADMINISTRATOR WHERE Admin_Username ='" + username + "' AND Admin_Password ='" + pwd + "'";
           SqlCommand cmd = new SqlCommand(sqlUserName, con);


           string CurrentName;
           CurrentName = (string)cmd.ExecuteScalar();

           if (CurrentName != null)
           {
               Session["UserAuthentication"] = username;
               Session.Timeout = 1;
               Response.Redirect("~/Admin/Default.aspx");
           }
           else
           {
               Session["UserAuthentication"] = "";
           }


Please help - SA
Posted
Comments
Sergey Alexandrovich Kryukov 18-Jun-13 12:27pm    
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.

(By the way, as I can see, you already got 2 abuse reports from different members on your account. If you collect more reports, your account may be automatically cancelled. I guess, the reason for such reports is that some of your answers aren't real ones.)

—SA
[no name] 19-Jun-13 11:02am    
Sorry guy(s), i just sow it now that the code i posted thinking is the solution was not the solution but the same problem i posted before. i will post the solution.

1 solution

ExecuteScalar returns first column of the first row of the result set of the query

refer

As your query goes like 'select * from ...', you resultset will contain all columns, so
to get a required column - use select col1, col2 from tablename.
 
Share this answer
 
Comments
[no name] 11-Jun-13 7:52am    
Thanx for your solution.. it is wekin Nycllly. :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900