PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
newbie question
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
newbie question
![]() |
newbie question |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
"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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#5 |
|
Guest
Posts: n/a
|
"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 |
|
|
|
#6 |
|
Guest
Posts: n/a
|
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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

