Пример #1
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string TextCombo = comboBox1.Text.ToString();

            if (TextCombo.Length == 0)
            {
                return;
            }
            int     CarID = int.Parse(comboBox1.Text.ToString());
            CarData tmp   = so.SelectCarData(CarID);

            textBox1.Text = tmp.CarOwner;
            textBox2.Text = tmp.CarNumber;
        }
Пример #2
0
        public CarData SelectCarData(int CarID)
        {
            CarData tmp = new CarData();

            SqlConnection con = new SqlConnection(ConnectionString);

            con.Open();
            String       Query     = @"select * from StudentTable where StudentIdentity=@StudentIdentity";
            SqlCommand   cmd       = new SqlCommand(Query, con);
            SqlParameter parmCarID = new SqlParameter("@StudentIdentity", CarID);

            cmd.Parameters.Add(parmCarID);
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                tmp.CarOwner  = rdr["StudentName"].ToString(); //Student Name == CarOwner
                tmp.CarNumber = rdr["ClassNumber"].ToString(); //Class Number == CarNumber
                tmp.CarID     = int.Parse(rdr["StudentIdentity"].ToString());
            }
            con.Close();
            return(tmp);
        }