0

I have a search form which the user has to enter values to search for a particular vehicle in the database. I want to assign a certain value in the database to a certain control on another page. how will I be able to do this? I have something like this

protected void Search_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("MyConnectionString");
            SqlParameter pm = new SqlParameter();
            conn.Open();
            string sql = "SELECT*FROM Vehicles WHERE Vehicle_Reg=@vReg";
            string sql1 = "SELECT*FROM Trailer WHERE Trailer_Reg=@tReg";
            string mySql = sql + sql1;
            SqlCommand cmd = new SqlCommand(mySql, conn);
            cmd.CommandText = mySql;
            cmd.Parameters.AddWithValue("@vReg", searchtext.Text);
            cmd.Parameters.AddWithValue("@tReg", chassisnum.Text);
            SqlDataReader dr;
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                //These TextBoxes are on another page
                txtReg.Text = dr["Registration"].ToString();
                txtMake.Text = dr["Make"].ToString();
                txtEngineNum.Text=dr["EngineNumber"].ToString();
                dr.Close();
            }
            conn.Close();
        }
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by murugavel84
0

I have a search form which the user has to enter values to search for a particular vehicle in the database. I want to assign a certain value in the database to a certain control on another page. how will I be able to do this? I have something like this

protected void Search_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("MyConnectionString");
            SqlParameter pm = new SqlParameter();
            conn.Open();
            string sql = "SELECT*FROM Vehicles WHERE Vehicle_Reg=@vReg";
            string sql1 = "SELECT*FROM Trailer WHERE Trailer_Reg=@tReg";
            string mySql = sql + sql1;
            SqlCommand cmd = new SqlCommand(mySql, conn);
            cmd.CommandText = mySql;
            cmd.Parameters.AddWithValue("@vReg", searchtext.Text);
            cmd.Parameters.AddWithValue("@tReg", chassisnum.Text);
            SqlDataReader dr;
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                //These TextBoxes are on another page
                txtReg.Text = dr["Registration"].ToString();
                txtMake.Text = dr["Make"].ToString();
                txtEngineNum.Text=dr["EngineNumber"].ToString();
                dr.Close();
            }
            conn.Close();
        }

Am not clear. Wat would u like to do exactly?

This topic has been dead for over six months. 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.