I'm doing a project where the Web application of ASP.Net should refer to a COM+ program to retrieve and validate or insert data from/to SQL server.
The problem is - that it is not retrieving and validating the data even though I have added the COM+ program.
Just to explain what I'm saying, here's the code snippet:
Expand|Select|Wrap|Line Numbers
- public class Login
- {
- SqlConnection con;
- SqlCommand cmd;
- SqlDataReader dr;
- SqlTransaction sqltrans;
- public string selectAdmin(string cusername, string cpassword)
- {
- try
- {
- con= new SqlConnection("server=localhost;user=sa;password=;database=Project");
- con.Open();
- sqltrans = con.BeginTransaction();
- cmd = new SqlCommand("SELECT cpassword FROM administrator WHERE cusername= "+cusername+"", con);
- cmd.Transaction=sqltrans;
- dr=cmd.ExecuteReader();
- dr.Read();
- if (dr.Read()==false)
- {
- MessageBox.Show("'"+cusername+"' not found");
- }
- else
- {
- if( dr.GetString(0) != cpassword.Trim())
- {
- MessageBox.Show("Password incorrect for '" + cusername + "'.");
- }
- }
- dr.Close();
- con.Close();
- }
- catch(Exception)
- {
- return "Exception Occurred";
- }
- return "OK!";
- }
Expand|Select|Wrap|Line Numbers
- private void Button1_Click(object sender, System.EventArgs e)
- {
- string status="";
- string username=(user_textbox.Text).Trim();
- string password=(pass_textbox.Text).Trim();
- string str;
- Project.Login obj = new Project.Login();
- str = obj.selectAdmin(user_textbox.Text, pass_textbox.Text);
- lblmessage.Text=str;
- if (status=="OK!")
- {
- Response.Redirect("AdminPage.aspx");
- }
- else
- {
- lblmessage.Text=status;
- }
- }
- private void cancel_button_Click(object sender, System.EventArgs e)
- {
- Response.Redirect("Home.aspx");
- }
- }
Please help.