开发者

c# display table from sql server on winform

开发者 https://www.devze.com 2023-01-23 13:29 出处:网络
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 itshould be a datachart, but it does

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

精彩评论

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

关注公众号