Mike Eghtebas
asked on
Populate a gridview control using data adapt...
I have been able to use data reader to populate gwCategory (a grid view control) using a data reader variable. But I need some help to do the same using a data adapter.
Question: How can I make the attached code work?
This is in vs 2010 for winForm.
Thank you.
Question: How can I make the attached code work?
This is in vs 2010 for winForm.
Thank you.
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.Configuration;
using System.Data.SqlClient;
namespace ado01_Connection
{
public partial class Form10 : Form
{
public Form10()
{
InitializeComponent();
}
private void Form10_Load(object sender, EventArgs e)
{
string cs = ConfigurationManager.ConnectionStrings["csDatabase"].ConnectionString;
SqlConnection con = new SqlConnection(cs);
using(con)
{
//SqlCommand cmd = new SqlCommand("SELECT [CategoryName],[Description],[Picture] FROM [Northwind].[dbo].[Categories];", con);
SqlDataAdapter da = new SqlDataAdapter("SELECT [CategoryName],[Description],[Picture] FROM [Northwind].[dbo].[Categories];", con);
DataSet ds = new DataSet();
da.Fill(ds);
//BindingSource source = new BindingSource();
//source.DataSource = ds;
gwCategory.DataSource = da;// source;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How can I make reference to an specific data adapter? Perhaps by name?
gwCategory.DataSource = ds.Tables(rdr1);
Mike