Hey all,
I know this is a long shot on a mac forum but I don't want to sign up to another forum just to ask a single question.
What it is is I have a web form that allows a company to make car bookings but what I would like it to do is when they select a car Make from a DropDownList, the Model DropDownList will populate itself from my database. I have figured out that I need to use a SqlDataReader and use a command etc.
Here is how far I have got so far.
All help is appreciated as usual .
Please though don't come on to this thread saying that I should use a asp forum, being honest I would rather ask here before asking over at a windows forum, which I don't want to do.
Thanks,
Stephen
I know this is a long shot on a mac forum but I don't want to sign up to another forum just to ask a single question.
What it is is I have a web form that allows a company to make car bookings but what I would like it to do is when they select a car Make from a DropDownList, the Model DropDownList will populate itself from my database. I have figured out that I need to use a SqlDataReader and use a command etc.
Here is how far I have got so far.
Code:
string make = makeDrop.SelectedItem.Text.ToString();
System.Data.SqlClient.SqlConnection conn =
new System.Data.SqlClient.SqlConnection(
ConfigurationManager.ConnectionStrings[
"VehiclesConnection"].ConnectionString);
conn.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand(
"SELECT Model FROM Car WHERE Make = @make", conn);
myCommand.Parameters.Add(
new SqlParameter(
"@make",
System.Data.SqlDbType.VarChar, 50, "Make"));
myCommand.Parameters["@make"].Value = make;
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
makeDrop.Items.Add(myReader["Model"].ToString());
}
conn.Close();
All help is appreciated as usual .
Please though don't come on to this thread saying that I should use a asp forum, being honest I would rather ask here before asking over at a windows forum, which I don't want to do.
Thanks,
Stephen