开发者

c# display table from sql server on winform

I am connecting to sql server using c#. How do I display the results of the below query on a winform? I would like to display this data set in a control. I believe it should be a datachart, but it does not matter to me.

// 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";

What is the best way to display the results of this query on a w开发者_如何学Cinform?


Drop a DataGridView on your form, and use this code to populate it

using(var connection = new SqlConnection(myConnectionString))
using(var adapter = new SqlDataAdapter(mySelectQuery, connection))
{
   var table = new DataTable();
   adapter.Fill(table);
   this.dataGridView.DataSource = table;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜