PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET newbie question

Reply

newbie question

 
Thread Tools Rate Thread
Old 13-09-2004, 03:50 PM   #1
Frederik
Guest
 
Posts: n/a
Default newbie question


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
Old 13-09-2004, 11:58 PM   #2
Frederik
Guest
 
Posts: n/a
Default Re: newbie question

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" <JayPondy@discussions.microsoft.com> 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
Old 14-09-2004, 05:57 AM   #3
Vagabond Software
Guest
 
Posts: n/a
Default Re: newbie question

"Frederik" <aerts_frederik@hotmail.com> wrote in message news:97271183.0409130550.432cb2bf@posting.google.com...
> / * 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
Old 14-09-2004, 09:18 AM   #4
Frederik
Guest
 
Posts: n/a
Default Re: newbie question


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/Uit.../DGridJobs1.png
http://users.skynet.be/am044448/Uit.../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:e3NRH8gmEHA.748@TK2MSFTNGP15.phx.gbl...
> "Frederik" <aerts_frederik@hotmail.com> wrote in message
> news:97271183.0409130550.432cb2bf@posting.google.com...
> / * 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
Old 14-09-2004, 10:25 AM   #5
Vagabond Software
Guest
 
Posts: n/a
Default Re: newbie question

"Frederik" <aerts_frederik@hotmail.com> wrote in message news:OiBt6rimEHA.2140@TK2MSFTNGP11.phx.gbl...
>
> 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
Old 14-09-2004, 11:10 AM   #6
Frederik
Guest
 
Posts: n/a
Default Re: newbie question

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:OcOQ6RjmEHA.2340@TK2MSFTNGP11.phx.gbl...

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off