private void getbindDataGrid()
{
cn= new SqlConnection(ConfigurationSettings.AppSettings["ds"]);
string strSQL="select medicine_id,medicine_name,medicine_price,medicine_stocks,medicine_end_date,ms.medicine_sort_name,s.storage_name,total=(medicine_price*medicine_stocks) from medicine m,medicineSort ms,storage s where m.medicine_sort_id=ms.medicine_sort_id and m.storage_id=s.storage_id and m.medicine_name like '%"+m_name.Text+"%'";//这里你可以设置你在TextBox中输入的查询信息,点击确定按钮触发下面的事件。这里是模糊查询。
da = new SqlDataAdapter(strSQL,cn);
cm = new SqlCommand(strSQL,cn);
ds = new DataSet();
cn.Open();
dr = cm.ExecuteReader();
if(dr.Read())
{
dr.Close();
da.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
message.InnerHtml="";
}
else
{
message.InnerHtml="<font size='2' color='red'><b>无此药品!请重新查找!</b></font>";
DataGrid1.Visible=false;
}
cn.Close();
}private void btnFind_Click(object sender, System.EventArgs e)
{
getbindDataGrid();
}
{
cn= new SqlConnection(ConfigurationSettings.AppSettings["ds"]);
string strSQL="select medicine_id,medicine_name,medicine_price,medicine_stocks,medicine_end_date,ms.medicine_sort_name,s.storage_name,total=(medicine_price*medicine_stocks) from medicine m,medicineSort ms,storage s where m.medicine_sort_id=ms.medicine_sort_id and m.storage_id=s.storage_id and m.medicine_name like '%"+m_name.Text+"%'";//这里你可以设置你在TextBox中输入的查询信息,点击确定按钮触发下面的事件。这里是模糊查询。
da = new SqlDataAdapter(strSQL,cn);
cm = new SqlCommand(strSQL,cn);
ds = new DataSet();
cn.Open();
dr = cm.ExecuteReader();
if(dr.Read())
{
dr.Close();
da.Fill(ds);
DataGrid1.DataSource=ds;
DataGrid1.DataBind();
message.InnerHtml="";
}
else
{
message.InnerHtml="<font size='2' color='red'><b>无此药品!请重新查找!</b></font>";
DataGrid1.Visible=false;
}
cn.Close();
}private void btnFind_Click(object sender, System.EventArgs e)
{
getbindDataGrid();
}
解决方案 »
- installshield 的问题
- 超时时间已到。在从池中获取连接之前超时时间已过。出现这种情况可能是因为所有池连接都已被使用并已达到最大池大小
- AdRotator自作聪明的路径问题
- javascript问题请大家帮我分析一下
- 为什么有的机器上没有Inetpub文件呢?
- 高手快来 ASPNET 中C# 把SQLserver数据库中的文章输出格式化?
- 如何绑定DropDownList
- 象各位高手请教:SqlDataReader读出多个结果集合,绑定多个Datalist控件上
- 招聘asp.net程序员
- 批量打印小票
- 200分求 dotnet框架,C#,asp.net等等关于dotnet的英文电子书籍
- 连接数据库的问题
private void binddatagrid(string select){
//在这之前重新执行Select
this.DataGrid1.DataSource = datatable;
this.DataGrid1.DataBind();
}只要你在点检索以后在调用一次这个方法就可以了。
注:筛选行的条件相当于Select的Where子句,可以按主键的ID等(如PKId=3)来筛选你所需要的行,此方法的返回值为DataRow[],这是一个数据行的数值,表示可以返回多行
注:筛选行的条件相当于Select的Where子句,可以按主键的ID等(如PKId=3)来筛选你所需要的行,此方法的返回值为DataRow[],这是一个数据行的数组,表示可以返回多行,如DataRow[2]表示第三行
Dim sqlstring As String = Sql.Text
Dim DS As New DataSet
Dim MyCommand As SqlDataAdapter
Dim MyConnection As New SqlConnection(ConfigurationSettings.AppSettings("SQLConnString"))
MyCommand = New SqlDataAdapter(sqlstring, MyConnection)
MyCommand.Fill(DS, "custom")
DataGrid1.DataSource = DS.Tables("custom")
DataGrid1.DataBind()
用C#得。