l--*_*''' 2 .net c# sql select sql-server-2008
我使用c#连接到sql server.如何在winform上显示以下查询的结果?我想在控件中显示此数据集.我认为它应该是一个数据广告,但对我来说并不重要.
// Initialize a connection string
string myConnectionString = "Provider=SQLOLEDB;Data Source=hermes;" +
"Initial Catalog=qcvaluestest;Integrated Security=SSPI;";
// Define the database query
string mySelectQuery = "select top 500 name, finalconc " +
"from qvalues where rowid between 0 and 25000";
Run Code Online (Sandbox Code Playgroud)
在winform上显示此查询结果的最佳方法是什么?
删除表单上的DataGridView,并使用此代码填充它
using(var connection = new SqlConnection(myConnectionString))
using(var adapter = new SqlDataAdapter(mySelectQuery, connection))
{
var table = new DataTable();
adapter.Fill(table);
this.dataGridView.DataSource = table;
}
Run Code Online (Sandbox Code Playgroud)