none
i got the error sql exception unhandled by user code RRS feed

  • Question

  • protected

     

    void Page_Load(object sender, EventArgs e)

    {

     

     

    SqlConnection con = new SqlConnection("Data Source=THEINF-C6BDB62B;Initial Catalog=mani;Integrated Security=True");

    con.Open();

     

    SqlCommand cmd = new SqlCommand("select * from login where username='" + TextBox1 .Text + "',and password='" + TextBox2 .Text + "'", con);

     

    SqlDataReader rdr = cmd.ExecuteReader();

     

    if (rdr.HasRows == true)

    {

    Response.Redirect(

    "default2.aspx");

    }

    cmd.Dispose();

    con.Close();

    }

    }

    Monday, August 23, 2010 5:22 AM

Answers

  • Hi Mani_ds,

    First it seems that there is a unnecessary comma in your sql statement. Please try this:

    SqlCommand cmd = new SqlCommand("select * from login where username='" + TextBox1.Text + "' And password='" + TextBox2.Text + "'", con);

    In additon, you can put a try- catch block in your code to catch the exception and could you please post the whole error message you got ?

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Mani_ds Wednesday, August 25, 2010 7:14 AM
    Tuesday, August 24, 2010 9:26 AM
    Moderator

All replies

  • Hi Mani_ds,

    First it seems that there is a unnecessary comma in your sql statement. Please try this:

    SqlCommand cmd = new SqlCommand("select * from login where username='" + TextBox1.Text + "' And password='" + TextBox2.Text + "'", con);

    In additon, you can put a try- catch block in your code to catch the exception and could you please post the whole error message you got ?

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Mani_ds Wednesday, August 25, 2010 7:14 AM
    Tuesday, August 24, 2010 9:26 AM
    Moderator
  • Hi Alex Liang,

           Thank u now i got the output

    Wednesday, August 25, 2010 7:17 AM