PC Review


Reply
Thread Tools Rate Thread

newbie question

 
 
Frederik
Guest
Posts: n/a
 
      13th Sep 2004
Hi all,

I've been working a little with data binding in ASP.NET, but know I
have to make a console application using C#. The way of filling a
DataGrid seems a bit different. I can't see a DataBind() method for
the DataGrid object. What I have is the following code:

/ * start code snippet */
string connectionString = "...";
OleDbConnection dbConnection = new OleDbConnection(connectionString);
OleDbCommand OleCmd = new OleDbCommand("SELECT * FROM sol_history
ORDER BY Verstuurd", dbConnection);
OleDbDataAdapter DbAdapter = new OleDbDataAdapter();
DataSet DbDataSet = new DataSet();
DbAdapter.SelectCommand = OleCmd;
DbAdapter.Fill(DbDataSet);
DGridJobs.SetDataBinding(DbDataSet, "");
/ * end code snippet */

The code fills the DataGrid in a 'weird' kind of way: it seems to have
something like a parent table. Could someone tell me what I need to do
in order to fill the DataGrid in a 'normal' way (with normal I mean
without the parent table stuff)?

Your time and answers are appreciated,
Fre
 
Reply With Quote
 
 
 
 
Frederik
Guest
Posts: n/a
 
      13th Sep 2004
Hi Jay,

Thanks for your input, but now the DataGrid is empty and there's no way to
navigate to my 'child table' (seems logical looking at the name of the
property). The thing is, that I only want to see the requested data in the
DataGrid, like it works in asp.net.

Regards,
Frederik

> "Jay Pondy" <(E-Mail Removed)> wrote:
> Set the datagrid's Navigation property to off.


>> "Frederik" wrote:
>> Hi all,
>> I've been working a little with data binding in ASP.NET, but know I
>> have to make a console application using C#. The way of filling a
>> DataGrid seems a bit different. I can't see a DataBind() method for
>> the DataGrid object. What I have is the following code:
>> / * start code snippet */
>> string connectionString = "...";
>> OleDbConnection dbConnection = new OleDbConnection(connectionString);
>> OleDbCommand OleCmd = new OleDbCommand("SELECT * FROM sol_history
>> ORDER BY Verstuurd", dbConnection);
>> OleDbDataAdapter DbAdapter = new OleDbDataAdapter();
>> DataSet DbDataSet = new DataSet();
>> DbAdapter.SelectCommand = OleCmd;
>> DbAdapter.Fill(DbDataSet);
>> DGridJobs.SetDataBinding(DbDataSet, "");
>> / * end code snippet */
>> The code fills the DataGrid in a 'weird' kind of way: it seems to have
>> something like a parent table. Could someone tell me what I need to do
>> in order to fill the DataGrid in a 'normal' way (with normal I mean
>> without the parent table stuff)?
>> Your time and answers are appreciated,
>> Fre



 
Reply With Quote
 
Vagabond Software
Guest
Posts: n/a
 
      14th Sep 2004
"Frederik" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> / * start code snippet */
> string connectionString = "...";
> OleDbConnection dbConnection = new OleDbConnection(connectionString);
> OleDbCommand OleCmd = new OleDbCommand("SELECT * FROM sol_history
> ORDER BY Verstuurd", dbConnection);
> OleDbDataAdapter DbAdapter = new OleDbDataAdapter();
> DataSet DbDataSet = new DataSet();
> DbAdapter.SelectCommand = OleCmd;
> DbAdapter.Fill(DbDataSet);
> DGridJobs.SetDataBinding(DbDataSet, "");
> / * end code snippet */
>
> The code fills the DataGrid in a 'weird' kind of way: it seems to have
> something like a parent table. Could someone tell me what I need to do
> in order to fill the DataGrid in a 'normal' way (with normal I mean
> without the parent table stuff)?


Use the DataMember property of the DataGrid.. For Example:

DGridJobs.DataMember = DbDataSet.Tables[0];

If the compiler complains about that line of code, the try this:

DGridJobs.DataMember = DbDataSet.Tables[0].TableName;

Have fun...

- carl
 
Reply With Quote
 
Frederik
Guest
Posts: n/a
 
      14th Sep 2004

Hi carl,

Thanks for your answer. Your second suggestion did compile, but it gave me
the same result as before:

http://users.skynet.be/am044448/Uitw...DGridJobs1.png
http://users.skynet.be/am044448/Uitw...DGridJobs2.png

It's not a problem for me to expand the DataSet till I get the wanted
result, but I'm not sure if the users of my program will find it as easy as
I do.

Regards,
Frederik


"Vagabond Software" <carlfenley-X-@-X-san.rr.com> wrote in message
news:(E-Mail Removed)...
> "Frederik" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> / * start code snippet */
> string connectionString = "...";
> OleDbConnection dbConnection = new OleDbConnection(connectionString);
> OleDbCommand OleCmd = new OleDbCommand("SELECT * FROM sol_history
> ORDER BY Verstuurd", dbConnection);
> OleDbDataAdapter DbAdapter = new OleDbDataAdapter();
> DataSet DbDataSet = new DataSet();
> DbAdapter.SelectCommand = OleCmd;
> DbAdapter.Fill(DbDataSet);
> DGridJobs.SetDataBinding(DbDataSet, "");
> / * end code snippet */
> The code fills the DataGrid in a 'weird' kind of way: it seems to have
> something like a parent table. Could someone tell me what I need to do
> in order to fill the DataGrid in a 'normal' way (with normal I mean
> without the parent table stuff)?


Use the DataMember property of the DataGrid.. For Example:
DGridJobs.DataMember = DbDataSet.Tables[0];
If the compiler complains about that line of code, the try this:
DGridJobs.DataMember = DbDataSet.Tables[0].TableName;
Have fun...
- carl


 
Reply With Quote
 
Vagabond Software
Guest
Posts: n/a
 
      14th Sep 2004
"Frederik" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
>
> Hi carl,
>
> Thanks for your answer. Your second suggestion did compile, but it gave me
> the same result as before


Setting the DataMember property should present the table you desire, as it does in this code block:

private void FillDataGrid()
{
string sqlSelect = "SELECT * FROM Customers";
sqlconn = new SqlConnection(ConnectionString);
sqlAdapter = new SqlDataAdapter(sqlSelect, sqlconn);

try
{
sqlAdapter.Fill(ds, "Customers");
}
finally
{
sqlconn.Close();
}

dataGrid1.DataSource = ds;
dataGrid1.DataMember = ds.Tables["Customers"].TableName;
}

If setting the DataMember property AFTER setting the DataSource property doesn't display the specified table, then try assigning the table to the DataSource property.

- carl
 
Reply With Quote
 
Frederik
Guest
Posts: n/a
 
      14th Sep 2004
Thanks a lot Carl, it works fine now !!! [I made a mistake first time.]

Frederik

--
--

"Vagabond Software" <carlfenley-X-@-X-san.rr.com> wrote in message
news:(E-Mail Removed)...

Setting the DataMember property should present the table you desire, as it
does in this code block:

private void FillDataGrid()
{
string sqlSelect = "SELECT * FROM Customers";
sqlconn = new SqlConnection(ConnectionString);
sqlAdapter = new SqlDataAdapter(sqlSelect, sqlconn);

try
{
sqlAdapter.Fill(ds, "Customers");
}
finally
{
sqlconn.Close();
}

dataGrid1.DataSource = ds;
dataGrid1.DataMember = ds.Tables["Customers"].TableName;
}

If setting the DataMember property AFTER setting the DataSource property
doesn't display the specified table, then try assigning the table to the
DataSource property.

- carl


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Real Newbie newbie question Dave Microsoft Excel New Users 1 10th Jan 2007 08:55 PM
Newbie Question - Subtraction Formula Question admiral_victory@iol.ie Microsoft Excel Misc 3 5th May 2006 06:50 PM
VPN question from newbie Kelvin Microsoft Windows 2000 RAS Routing 1 17th Apr 2004 04:34 AM
Arraylist simple question (newbie) OT (for a CF project, but not necessarily a CF question?) Keith R Microsoft Dot NET Compact Framework 1 2nd Dec 2003 11:27 PM
Question re: different shells - newbie question PJC Windows XP Embedded 1 26th Nov 2003 12:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 PM.