且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用列数据从数据表中检索数据行

更新时间:2023-01-19 15:28:34

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.