.NETGURU
newbie question
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Frederik
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 to this message...
 
    
Jay Pondy (VIP)
Set the datagrid's Navigation property to off.

"Frederik" wrote:

[Original message clipped]

Reply to this message...
 
    
Frederik
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

[Original message clipped]

Reply to this message...
 
    
Vagabond Software
"Frederik" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address...
[Original message clipped]

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 to this message...
 
    
Frederik
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/Uitwisseling/DGridJobs1.png
http://users.skynet.be/am044448/Uitwisseling/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" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

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 to this message...
 
    
Vagabond Software
"Frederik" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address...
[Original message clipped]

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 to this message...
 
    
Frederik
Thanks a lot Carl, it works fine now !!! [I made a mistake first time.]

Frederik

--
--

"Vagabond Software" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...

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 to this message...
 
 
System.Data.DataSet
System.Data.OleDb.OleDbCommand
System.Data.OleDb.OleDbConnection
System.Data.OleDb.OleDbDataAdapter
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.Web.UI.WebControls.DataGrid
System.Windows.Forms.DataGrid




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification