Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Register FAQ Community Calendar Today's Posts Search Log in
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 04-05-2009, 01:48 PM   #1
Baseband Member
 
Join Date: Nov 2008
Posts: 91
Default help with BindingSources

I need some help with BindingSources (in C#).

This is what I'm working on:

From the C# tutorial at Programmer's Heaven (http://www.programmersheaven.com/2/Les_CSharp_13_p9):

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?
__________________

BobLewiston is offline   Reply With Quote
Old 04-06-2009, 08:01 AM   #2
In Runtime
 
Daeva's Avatar
 
Join Date: Dec 2005
Posts: 407
Send a message via AIM to Daeva Send a message via MSN to Daeva Send a message via Yahoo to Daeva
Default Re: help with BindingSources

I've never heard of dgDetails. However, all you need to do to bind to a datagrid control is to use it's DataSource property.
Also, using the dataAdapter is an extra step.

Try this instead:

Code:
string connectionString = "server=P-III; database=programmersheaven; uid=sa; pwd=;";
    SqlConnection conn = new SqlConnection (connectionString);
    string cmdString = "SELECT * FROM article";
    SqlCommand cmd = new SqlCommand(cmdString,conn);
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(rdr,LoadOption.Upsert);
conn.Close();
MyDataGridControl.DataSource = dt;
__________________

__________________
**Official Self-proclaimed glorified excessive (insert additional adjectives here) post editor/modifier.
Edit = Best feature ever
http://www.twitter.com/xDaevax
Daeva is offline   Reply With Quote
Old 05-10-2009, 10:34 PM   #3
Baseband Member
 
Join Date: Sep 2004
Posts: 95
Default Re: help with BindingSources

The above will definitely work.

Just to clarify so there is no confusion, I believe dgDetails is a Data Grid control that was created and defined earlier in code.
__________________
As the sun sets, the earth shall prepare
ksb007 is offline   Reply With Quote
Old 05-10-2009, 10:58 PM   #4
Fully Optimized
 
vampist's Avatar
 
Join Date: Oct 2008
Location: USA
Posts: 2,404
Default Re: help with BindingSources

Quote:
Originally Posted by ksb007 View Post
The above will definitely work.

Just to clarify so there is no confusion, I believe dgDetails is a Data Grid control that was created and defined earlier in code.

Post date.
vampist is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 01:16 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0