hi all,
am doing windows application with c#.net,
my problem is i have created two connection string with different database in my application
the thing is i need to log in my application,
for example,
my first database login id is:
user name: test
pwd : test
my second database login id is:
username : testing
pwd: testing123
what i want to do is when i log in to my first database login details ,its i need to go form1.cs
and when i log in to my second database login details, its i need to go form2.cs
the above two thing i have write the code in button click event,
i done this code in my side but i cant to redirect the specific page like form1.cs or form2.cs.
please find out the below code where i did mistakes and let me know the solution please..
my code is:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace tarriff_design_page
{
public partial class testing : Form
{
string s = @"Data Source=MBTA2A2A2A00005\SQLEXPRESS;Initial Catalog=tarrif;User ID=sa;Password=sa";
string s1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\stellus\Database1.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection();
SqlConnection con1 = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlCommand cmd1 = new SqlCommand();
SqlDataReader dr;
SqlDataReader dr1;
public testing()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
con = new SqlConnection(s);
con1 = new SqlConnection(s1);
con.Open();
cmd = new SqlCommand("select username,password from login", con);
cmd1 = new SqlCommand("select username,password from login",con1);
dr = cmd.ExecuteReader();
dr1 = cmd1.ExecuteReader();
if (dr==cmd.ExecuteReader())
{
while (dr.Read())
{
string username = textBox1.Text;
string password = textBox2.Text;
if (dr["username"].ToString() == username && dr["password"].ToString() == password)
{
Home hmpage = new Home();
//hmpage.label1.Text = txtusername.Text;
hmpage.Text = (textBox1.Text) + System.DateTime.Now.ToString();
hmpage.Show();
this.Hide();
}
else
{
MessageBox.Show("The username or password you entered is incorrect!", "Logon Message!");
}
con.Close();
dr.Close();
}
}
else if (dr1 == cmd1.ExecuteReader())
{
while (dr1.Read())
{
string user1 = textBox1.Text;
string pwd1 = textBox2.Text;
if (dr1["username"].ToString() == user1 && dr1["password"].ToString() == pwd1)
{
Admin ad = new Admin();
ad.Show();
}
else
{
MessageBox.Show("invalid username/password");
}
con.Close();
dr.Close();
}
}
}
catch (Exception ex)
{
}
}
}
}
thanks in advance...