Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview?
Set datasources for each column in datagridview? Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Go Back  Xtreme Visual Basic Talk > > > Set datasources for each column in datagridview?


Reply
 
Thread Tools Display Modes
  #21  
Old 04-13-2006, 11:57 AM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default


Forgive me, I'm not explaining very well.
I have 3 tables and I filled a dataset with all 3 tables.
Now I want to bind that dataset to a datagrid, but I don't want all of the fields from all 3 tables, just 2 of the fields from one table in two columns that are read-only and a field from one of the other tables in a third column that will be saved back to the database. I then want to display data in the fourth column that is computed on the side and will not be saved.

I just don't know how to tell the columns in the datagrid which field they should be showing.
Normally I would just bind the datagrid to a dataset and let it show everything, but here I don't want to do that.
Thanks for the patience, hope that came out a little clearer.
Reply With Quote
  #22  
Old 04-13-2006, 12:02 PM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

I think part of my problem is I'm used to using 1 table per dataset.

So where I would use:

datagrid.datasource = dataset
datagrid.datamember="tablename"

I only get data from 1 table to show up. I'm trying to do the above to individual columns to set the datasource and datamember.

Last edited by wolfmanyoda; 04-13-2006 at 12:03 PM. Reason: syntax
Reply With Quote
  #23  
Old 04-13-2006, 12:09 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

If the columns in the other tables are related to the first table via a foreign key, then you ought to be using a join to retrieve the data from the three tables into one data table. If the columns are not related, having them in the same table would confuse things no?
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
  #24  
Old 04-13-2006, 01:05 PM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

Well, as I said earlier, my SQL is pretty basic.
I did try this bit of code, but I get nothing in datagrid:

Code:
Dim dsProjects As DataSet = New DataSet Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & _ "my valid path is here" Dim SQLStatement As String SQLStatement = "SELECT Tasks.TaskID, " & _ "Tasks.TaskName, " & _ "Tasks.TaskHourlyCost, " & _ "Projects.ProjectID, " & _ "ProjectTaskTime.ProjectID, " & _ "ProjectTaskTime.TaskID, " & _ "ProjectTaskTime.Time " & _ "FROM Tasks, Projects, ProjectTaskTime " & _ "WHERE (Tasks.TaskID = ProjectTaskTime.TaskID) " & _ "AND (ProjectTaskTime.ProjectID = Projects.ProjectID) " Dim oleDBConn As New OleDb.OleDbConnection(conn) Dim adapter As New OleDb.OleDbDataAdapter Try adapter.SelectCommand = New OleDb.OleDbCommand(SQLStatement, oleDBConn) adapter.Fill(dsProjects) oleDBConn.Close() Me.dgvProjects.DataSource = dsProjects Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Information) End Try

I know I said I only want a few columns but I figured my SQL statement should include the key fields so it can grab the correct related data.
Reply With Quote
  #25  
Old 04-13-2006, 01:12 PM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

does dsProjects contain any data? If you go to the debug window or any immediate window after your .Fill command and do this:

?dsProjects.Tables(0).Rows.Count.ToString()

Do you get any errors or a return of 0?

My first guess is your query isn't returning any records. My second guess is your DataSet for some reason has a header table or is being populated with multiple tables. So you could do:

Code:
Me.dgvProjects.DataSource = dsProjects.Tables(0)

But I've seen that only in rare occassions and their is an MSDN article that explains exactly what causes that, and I can't recall off hand
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #26  
Old 04-13-2006, 01:20 PM
IUnknown's Avatar
IUnknown IUnknown is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Oct 2004
Location: Montréal
Posts: 1,135
Default

Er, you need to open the connection before calling the Fill method.
__________________
win7 : vs 2008 : .Net 3.5
Reply With Quote
  #27  
Old 04-13-2006, 01:23 PM
wolfmanyoda's Avatar
wolfmanyoda wolfmanyoda is offline
Regular
 
Join Date: Jan 2003
Location: Indiana
Posts: 90
Default

After my Fill, dsProjects does have data.
Your line here:
Code:
Me.dgvProjects.DataSource = dsProjects.Tables(0)
did the trick. Thank you for all of your help.
I never would have thought to use dsProjects.Tables(0)
Reply With Quote
  #28  
Old 04-13-2006, 01:28 PM
MKoslof's Avatar
MKoslofSet datasources for each column in datagridview? MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Remember, DataSets are containers, they aren't the actual DataObject. For example:

Code:
Dim ds as New DataSet()

Create a new DataSet but a Grid has nothing here to "bind" to, a workable set of data. It will bind to an empty container

When you fill a DataSet or build a DataSet by scratch you either explicitally add a DataTable or via your fill command, .Net creates the object for you. I *believe* (but I can't recall off hand, as I said before) if you have a JOINED recordset some extra processing is conducted in the DataSet object, I'd have to refresh myself on this. So in order to tell the DataGrid what data object to use, supply the table index, or table name, if you named your table.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview? Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview? Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
 
Set datasources for each column in datagridview?
Set datasources for each column in datagridview?
 
-->