如何使用列数据从数据表中检索数据行
我在数据表中有一些数据我想根据值从数据表中检索一行
例如
数据表中的数据喜欢
1 prasad hyderabad b.tech cse 2015
如果我在文本框中输入任意1或prasad我想显示行中的gridview如何才能实现这一点请大家
谢谢
i have some data in datatable i want to retrieve a row from datatable based on value
for example
the data in datatable like
1 prasad hyderabad b.tech cse 2015
if i enter the any 1 or prasad in textbox i want to display the row in gridview how i can i achieve this one please guys
thanks
GridView1.DataSource=dt; // dt is Your DataTable
GridView1.DataBind();
根据以下查询,您可以搜索表格中的数据并将其显示给网格视图
based upon the below query you can search the data in table and display it to the grid view
DataTable objdt = new DataTable();
var searchval = Textbox1.Text
var searchval=Textbox1.Text
string query =@ "select * from TableName where name like '%" + searchval+ "%' or id like'%" + searchval+ "%'
SqlDataAdapter da = new SqlDataAdapter(query, con);
con.Open();
da.Fill(objdt);
con.Close();
if (objdt.Rows.Count > 0)
{
GridView1.DataSource = objdt;
GridView1.DataBind();
}
你好,
您可以使用LINQ从中提取任何行数据表
Hello ,
You can use LINQ to extract any row from the datatable
DataRow[] result = table.Select("Size >= 230);
尺寸在上面一行参考列名。
只需要在table.select中定义条件(条件)
一旦得到行数组你可以在它上面应用循环。
"Size" in above line refer to Column name.
just need to define the condition in table.select("Condition")
Once you get the row array you can apply loop over it.
foreach (DataRow row in result)
{
Console.WriteLine("{0}, {1}", row[0], row[1]);
}
谢谢。
希望这会有所帮助。
Thanks.
Hope this helps.