private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection ("Data Source=.\\SQLEXPRESS;Initial Catalog=test1;Integrated Security=True");
SqlCommand cmd = new SqlCommand("dbo.get", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@userName", textBox1.Text);
try
{
con.Open();
SqlDataReader read = cmd.ExecuteReader();
read.Read();
if (read.HasRows)
{
textBox2.Text = read["password"].ToString();
Form2 fr2 = new Form2();
fr2.Show();
con.Close();
}
else
{
MessageBox.Show("passworedis wrong");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
con.Close();
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection ("Data Source=.\\SQLEXPRESS;Initial Catalog=test1;Integrated Security=True");
SqlCommand cmd = new SqlCommand("dbo.register", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@userName", textBox1.Text);
cmd.Parameters.AddWithValue("@password", textBox2.Text);
try
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("done");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
con.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=test1;Integrated Security=True");
SqlCommand cmd = new SqlCommand("dbo.get", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue ("@userName", textBox2.Text);
try
{
con.Open();
cmd.ExecuteNonQuery();
SqlDataReader read = cmd.ExecuteReader();
read.Read();
if (read.HasRows)
{
textBox1.Text = read["password"].ToString();
}
else
{
MessageBox.Show("w");
}
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
throw;
}
IS THIS THE SHORTEST WAY TO DO THIS KIND OF THING