using System; using System.Data; using System.Data.SqlClient; using System.Windows.Forms; namespace GridDataSetBindingSourceAndTableAdapterDynamicExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string connectionString = "data source=localhost;initial catalog=TestCompleteTest;persist security info=True;Integrated Security=SSPI"; using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand("SELECT * FROM Names", conn)) { conn.Open(); DataSet ds = new DataSet(); SqlDataAdapter da = new SqlDataAdapter { SelectCommand = cmd }; da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } } } } }Taken from here Example download from here
Grid, DataSet, BindingSource and TableAdapter another example
- Details
- Written by: Stanko Milosev
- Category: Windows Forms
- Hits: 1462
Another example of DataGridView this time with run-time DataSource binding: