请如何在名称和/或日期中写出搜索代码,以及如何在数据网格中显示数据 [英] Please how to Writting the search code by name and\or date and data display in datagrid
本文介绍了请如何在名称和/或日期中写出搜索代码,以及如何在数据网格中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按名称和/或日期写搜索代码,并在datagrid中显示数据
通过c#和sql server.
Writting the search code by name and\or date and data display in datagrid
by c# and sql server.
推荐答案
尝试此步骤.
1.连接到Sql
2.填充数据集
3.制作数据视图
4.将其绑定到datagrid
5.在UI(c#)中为名称/日期过滤器提供输入选项
6.将值传递到dataview并使用如下所示的过滤器
Try this steps.
1. Make connection to Sql
2. Fill dataset
3. make dataview
4. bind it to datagrid
5. Give input option in UI (c#) for name/date filter
6. pass the value to dataview and use filter as below
dv.Table.Select("name = "+ txtName.Text)
7.将结果绑定到datagrid
7. Bind the result to datagrid
希望这会有所帮助
Hope this helps
try
{
SqlConnection oConn = new SqlConnection();
oConn.ConnectionString = "Data Source=EXPERIENCE;database=Test;user=sa;password=admin1990";
oConn.Open();
string strDate=String.Format("{0:dd/MMM/yyyy}", dtpDate.Value);
string strSQL = "Select * from attendance where CheckIn=''" + strDate + "''";
if (txtName.Text.Trim().Length != 0)
strSQL = strSQL + " and name like ''%"+ txtName.Text +" %''";
SqlCommand oCmd = new SqlCommand(strSQL,oConn);
var da = new SqlDataAdapter(oCmd);
var nwSet = new DataSet();
da.Fill(nwSet);
dg.DataSource = nwSet.Tables[0].DefaultView;
MessageBox.Show ("Sucess");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
这篇关于请如何在名称和/或日期中写出搜索代码,以及如何在数据网格中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文