using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace DataSetExample { public partial class Form1 : Form { SqlConnection objConnection = new SqlConnection("server=localhost;database=Pubs;"+ "IntegratedSecurity=true"); SqlDataAdapter objDataAdapter = new SqlDataAdapter(); DataSet objDataSet = new DataSet(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { objDataAdapter.SelectCommand = new SqlCommand(); objDataAdapter.SelectCommand.Connection = objConnection; objDataAdapter.SelectCommand.CommandText = "SELECT au_lname, au_fname, title, price " + "FROM authors " + "JOIN titleauthor ON authors.au_id = " + "titleauthor.au_id " + "JOIN titles ON titleauthor.title_id = " + "titles.title_id " + "ORDER BY au_lname, au_fname"; objDataAdapter.SelectCommand.CommandType = CommandType.Text; objConnection.Open(); objDataAdapter.Fill(objDataSet, "authors"); objConnection.Close(); grdAuthorTitles.AutoGenerateColumns = true; grdAuthorTitles.DataSource = objDataSet; grdAuthorTitles.DataMember = "authors"; objDataAdapter = null; objConnection = null; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)