-2
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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Geekitygeek
1

It helps if you offer a little more information about what "THIS SORT OF THING" is. You have two button1_click event handlers there, and if i've read it right, you are displaying the password instead of checking it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.