ASP.NET中怎么从下拉列表框怎么读数据进数据库
展开全部
String connectiongstring = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection sqlcon = new SqlConnection(connectiongstring);
string Brand = BDropDownList.SelectedValue.ToString();//下拉列表
string CmdText = "SELECT Model FROM [CarType] WHERE Brand=\'" + Brand + "\'";
SqlCommand sqlcom = new SqlCommand(CmdText, sqlcon);
try
{
sqlcon.Open();
SqlDataReader dr = sqlcom.ExecuteReader();
。。。。。。。。。。
}
catch (SqlException ex)
{
}
//清理
finally
{
if (sqlcon != null)
{
sqlcon.Close();
}
}
还有需要注意的是autopostback属性设置成true
SqlConnection sqlcon = new SqlConnection(connectiongstring);
string Brand = BDropDownList.SelectedValue.ToString();//下拉列表
string CmdText = "SELECT Model FROM [CarType] WHERE Brand=\'" + Brand + "\'";
SqlCommand sqlcom = new SqlCommand(CmdText, sqlcon);
try
{
sqlcon.Open();
SqlDataReader dr = sqlcom.ExecuteReader();
。。。。。。。。。。
}
catch (SqlException ex)
{
}
//清理
finally
{
if (sqlcon != null)
{
sqlcon.Close();
}
}
还有需要注意的是autopostback属性设置成true
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询