code problem

Aug 7 2013 8:00 AM

private void button1_Click(object sender, EventArgs e)

{

        string data = textBox1.Text;

        Form2 form2=new Form2();

        form2.LoadData(data);

        this.Hide();

        form2.Show();

}


In Form 2
----------
Declare 3 TextBox and write the below method

public void LoadData(string data)

{

            using (SqlConnection conn = new SqlConnection(@"Data Source=SQLEXPRESS;Initial Catalog=MyDb;Persist Security Info=True;User ID=MyUser;Password=MyPassword"))

        {

                if (conn.State == ConnectionState.Closed)

                    conn.Open();

                string sql = "Select no,name,age from YourTable where no=@no";

                SqlCommand cmd = new SqlCommand(sql, conn);

                cmd.Parameters.AddWithValue("@no", data);

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())

                {

                    textBox1.Text = reader["no"].ToString();

                    textBox2.Text = reader["name"].ToString();

                    textBox3.Text = reader["age"].ToString();

                }

                reader.Close();

                if (conn.State == ConnectionState.Open)

                    conn.Close();

                conn.Dispose();

            }

}

this code is in c# and i want to convert to vb.net ..please help how to do that ?


Answers (3)