Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with BindingSources

Status
Not open for further replies.

thedougster

Programmer
Jan 22, 2009
56
US
I need some help with BindingSources.

This is what I'm working on:

From the C# tutorial at Programmer's Heaven (
private void btnLoadData_Click(object sender, System.EventArgs e)
{
string connectionString = "server=P-III; database=programmersheaven; uid=sa; pwd=;";
SqlConnection conn = new SqlConnection (connectionString);
string cmdString = "SELECT * FROM article";
SqlDataAdapter dataAdapter = new SqlDataAdapter (cmdString, conn);
DataSet ds = new DataSet ();
dataAdapter.Fill (ds, "article");
dgDetails.SetDataBinding (ds, "article");
}

When I try to compile this, I get the following error: "The name 'dgDetails' does not exist in the current context".

I have just been told that dgDetails is a BindingSource. I'm a newbie, so I'm not familiar with BindingSources.

Could you tell me what I need to include in my code to get the compiler to recognize the dgDetails BindingSource and compile my app?
 
you'll need to define dbDetails, probably in your Form class. It's defined like this:

private BindingSource dgDetails;

then before using be sure to:

dgDetails = new BindingSource();

Then it should be usable.

I assumed you would want to set it as a private variable in the class scope but you can define it wherever you want.


Travis Hawkins
 
dgDetails is the ID of the datagridview itself. If you have not given it this ID, either do so (to stay in synch with the article you're reading) or change 'dgDetails' to DataGridView1, or whatever default ID the grid was given and you should be in business. The article also looks as if it fails to mention that you may need to add these using statements:

using System.Data;
using System.Data.SqlClient;

I usually work in a web environment, so please forgive me if I'm mistaken about the using statements. good luck!



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top