asp.net 开发用vb语言编写“查找”功能代码
DropDownList控件+DataGrid控件+SQLServer实现查找并显示信息。根据DropDownList选择的内容搜索数据库中的字段用DataGrid输出信...
DropDownList控件+DataGrid控件+SQL Server 实现查找并显示信息。根据DropDownList选择的内容搜索数据库中的字段用DataGrid输出信息,需要完整的代码。
展开
2013-12-12
展开全部
SqlConnection conn = new SqlConnection("Server=WWW-2270B8786BB;Integrated Security=SSPI;Database=Northwind;Uid=sa;Pwd=sa;"); protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ string sqlStr = "select * from Orders ";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet();
da.Fill(ds);
this.DropDownList1.DataSource = ds.Tables[0].DefaultView;
DropDownList1.DataTextField = "CustomerID";
DropDownList1.DataValueField = "OrderID";
DropDownList1.DataBind();
} }
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string val = DropDownList1.SelectedValue; string sqlStr = "select * from Orders where OrderID= '" + val + "'";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet();
da.Fill(ds); this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
DataGrid1.DataBind();
}
{
if (!IsPostBack)
{ string sqlStr = "select * from Orders ";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet();
da.Fill(ds);
this.DropDownList1.DataSource = ds.Tables[0].DefaultView;
DropDownList1.DataTextField = "CustomerID";
DropDownList1.DataValueField = "OrderID";
DropDownList1.DataBind();
} }
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string val = DropDownList1.SelectedValue; string sqlStr = "select * from Orders where OrderID= '" + val + "'";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet();
da.Fill(ds); this.DataGrid1.DataSource = ds.Tables[0].DefaultView;
DataGrid1.DataBind();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询