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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.