Problem with Login

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • suganya
    New Member
    • Dec 2006
    • 39

    Problem with Login

    Hi


    To check the login I have given the coding as

    [code=cpp]
    protected void imgLogin1_Click (object sender, ImageClickEvent Args e)
    {
    SqlConnection con;
    SqlCommand cmd;
    string str;
    SqlDataReader rd;
    str = "user id=sa;password= cast;database=H ello_Dr;server= AURORA-SERVER";
    con = new SqlConnection(s tr);
    try
    {
    con.Open();
    }
    catch
    {
    }
    cmd = new SqlCommand();
    cmd.Connection = con;
    cmd.CommandText = "select count(UserId1) from DoctorRegistrat ion2 where UserId1='" + txtUserId.Text. ToString() + "' and Password1= '" + txtPassword.Tex t.ToString() + "'";
    Int16 cnt;
    cnt = cmd.ExecuteScal ar();
    if (cnt <= 0)
    {
    Response.Write( "Un authorise user");
    }
    else
    {
    Response.Write( "Authorise user");
    }
    }[/code]

    ERROR: Error 1 Cannot implicitly convert type 'object' to 'short'. An explicit conversion exists (are you missing a cast?)
    Last edited by Frinavale; May 26 '08, 08:36 PM. Reason: added [code] tags
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    These are your offending lines:

    Originally posted by suganya
    ...
    Int16 cnt;
    cnt = cmd.ExecuteScal ar();
    ...
    ERROR: Error 1 Cannot implicitly convert type 'object' to 'short'. An explicit conversion exists (are you missing a cast?)
    ExecuteScalar() returns an object. You need to cast it properly. Try this:
    Code:
    Int16 cnt;
    cnt = Convert.ToInt16(cmd.ExecuteScalar());

    Comment

    Working...