473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ds. relations problem with dataset

Hi. I have the code working just fine except all the data isn't coming up with the ds.relations code. Could you see what I'm doing wrong or what else I need to add. Code down below
Dim adapter As OdbcDataAdapter = New OdbcDataAdapter(command)
Dim ds As DataSet = New DataSet()
adapter.SelectCommand = New OdbcCommand("select rmsfiles2.obcop200.line#, rmsfiles2.obcop200.ordno, rmsfiles2.obcop200.quano, rmsfiles2.obcop200.quana, rmsfiles2.obcop200.quans, rmsfiles2.obcop200.c2rdt, rmsfiles2.obcop200.unitm, rmsfiles2.obcop200.actsp, rmsfiles2.obcop200.prdno from rmsfiles2.obcop200 where ordno = " & Order.ToString(), myConnection)
adapter.Fill(ds, "OBCOP200")

adapter.SelectCommand = New OdbcCommand("select rmsfiles2.mspmp100.ptyp1, rmsfiles2.mspmp100.ptyp2, rmsfiles2.mspmp100.descp, rmsfiles2.mspmp100.prdno from rmsfiles2.obcop200 inner join rmsfiles2.mspmp100 on rmsfiles2.obcop200.prdno = rmsfiles2.mspmp100.prdno where rmsfiles2.obcop200.ordno = " & Order.ToString(), myConnection)
adapter.Fill(ds, "MSPMP100")

ds.Tables(0).TableName = "OBCOP200"
ds.Tables(1).TableName = "MSPMP100"
Dim relation As New DataRelation("OBCOP200MSPMP100", ds.Tables("OBCOP200").Columns("prdno"), ds.Tables("MSPMP100").Columns("prdno"), False)
' ds.Relations.Add("OBCOP200MSPMP100", ds.Tables("OBCOP200").Columns("prdno"), ds.Tables("MSPMP100").Columns("prdno"), True)
ds.Relations.Add(relation)

gridview1.DataSource = ds
gridview1.DataBind()
If ds.Tables(0).Rows.Count = 0 Then
lbl_error.Visible = True
gridview1.Visible = False
Else
lbl_error.Visible = False
gridview1.Visible = True
End If

If ds.Tables(1).Rows.Count = 0 Then
lbl_error.Visible = True
gridview1.Visible = False
Else
lbl_error.Visible = False
gridview1.Visible = True
End If
Sep 27 '07 #1
14 1668
davef
98
The code looks alright to me. What's the error you're getting again?
Sep 27 '07 #2
thats the thing I'm not getting no error I'm not getting 3 columns that I need from the table
The code looks alright to me. What's the error you're getting again?
Sep 27 '07 #3
davef
98
thats the thing I'm not getting no error I'm not getting 3 columns that I need from the table
Which columns are missing from the dataset?
Sep 27 '07 #4
There are the ptyp1, ptyp2, and the descp fields that are missing.
Which columns are missing from the dataset?
Sep 27 '07 #5
davef
98
There are the ptyp1, ptyp2, and the descp fields that are missing.
Is your gridview supposed to have hierarchical Master-Detail structure?
Sep 27 '07 #6
I don't know. Does it
Is your gridview supposed to have hierarchical Master-Detail structure?
Sep 27 '07 #7
davef
98
I don't know. Does it
I could post the code that builds a Master-Detail DataGrid if that would help your problem.
Sep 27 '07 #8
I could post the code that builds a Master-Detail DataGrid if that would help your problem.

sure it wouldn't hurt to try it. I have a gridview not a datagrid
Sep 27 '07 #9
davef
98
sure it wouldn't hurt to try it. I have a gridview not a datagrid
You must have Nortwind SQL Server db installed for this sample to run. Place a DataGrid (not DataGridView) object on the form. Here's you Form_Load event handler implementation:
Expand|Select|Wrap|Line Numbers
  1.         private void Form1_Load( object sender, EventArgs e )
  2.         {
  3.             string szConn = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=server-name";
  4.             string szSQL = "select * from dbo.Categories";
  5.             SqlConnection conn = new SqlConnection( szConn );
  6.             SqlCommand command = new SqlCommand( szSQL );
  7.  
  8.             if( conn.State != ConnectionState.Open )
  9.                 conn.Open();
  10.  
  11.             command.Connection = conn;
  12.             SqlDataAdapter adapter = new SqlDataAdapter( command );
  13.             DataSet ds = new DataSet();
  14.             adapter.Fill( ds, "Categories" );
  15.  
  16.             szSQL = "select * from Products";
  17.             command.CommandText = szSQL;
  18.             adapter.Fill( ds, "Products" );
  19.  
  20.             DataRelation relation = new DataRelation(
  21.                 "CategoryProduct", ds.Tables["Categories"].Columns["CategoryID"],
  22.                 ds.Tables["Products"].Columns["CategoryID"], true );
  23.             ds.Relations.Add( relation );
  24.  
  25.  
  26.             this.dataGrid1.DataSource = ds;
  27.             this.dataGrid1.DataMember = "Categories";
  28.             conn.Close();
  29.         }
  30.  
Sep 27 '07 #10
I don't have that installed on my machine so It don't help me. Its all the same code except the sql commands and of course the tables

You must have Nortwind SQL Server db installed for this sample to run. Place a DataGrid (not DataGridView) object on the form. Here's you Form_Load event handler implementation:
Expand|Select|Wrap|Line Numbers
  1.         private void Form1_Load( object sender, EventArgs e )
  2.         {
  3.             string szConn = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=server-name";
  4.             string szSQL = "select * from dbo.Categories";
  5.             SqlConnection conn = new SqlConnection( szConn );
  6.             SqlCommand command = new SqlCommand( szSQL );
  7.  
  8.             if( conn.State != ConnectionState.Open )
  9.                 conn.Open();
  10.  
  11.             command.Connection = conn;
  12.             SqlDataAdapter adapter = new SqlDataAdapter( command );
  13.             DataSet ds = new DataSet();
  14.             adapter.Fill( ds, "Categories" );
  15.  
  16.             szSQL = "select * from Products";
  17.             command.CommandText = szSQL;
  18.             adapter.Fill( ds, "Products" );
  19.  
  20.             DataRelation relation = new DataRelation(
  21.                 "CategoryProduct", ds.Tables["Categories"].Columns["CategoryID"],
  22.                 ds.Tables["Products"].Columns["CategoryID"], true );
  23.             ds.Relations.Add( relation );
  24.  
  25.  
  26.             this.dataGrid1.DataSource = ds;
  27.             this.dataGrid1.DataMember = "Categories";
  28.             conn.Close();
  29.         }
  30.  
Sep 27 '07 #11
davef
98
I don't have that installed on my machine so It don't help me. Its all the same code except the sql commands and of course the tables
A DataGridView is not hierarchical by design so you can present the contents of only one table of the dataset at a time. Try to set the DataMember property to the specific table and massage the data beforehand.
Sep 27 '07 #12
A DataGridView is not hierarchical by design so you can present the contents of only one table of the dataset at a time. Try to set the DataMember property to the specific table and massage the data beforehand.
well i added the datamember to the first table between the datasource and databind. the massage part i dont' know what you are talking about
Sep 27 '07 #13
davef
98
well i added the datamember to the first table between the datasource and databind. the massage part i dont' know what you are talking about
Does your first datatable contain the fields you're missing from the grid now?
Sep 27 '07 #14
the fields that im missing is in the second table i tried both tables for the datamember and still missing
Does your first datatable contain the fields you're missing from the grid now?
Sep 27 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: womber | last post by:
What do you think is the best design approach when your trying to get nested XML results from dataSet.GetXML. Define the relations in the dataset or apply an XSLT stylesheet to nest the results by...
0
by: Joe Van Meer | last post by:
Hi all, I have a question regarding data relations within a data set. Say I have 3 tables named CLIENT, BOOKING and EMPLOYEE and I wanted to relate the first two tables (CLIENT AND BOOKING)...
1
by: Ravi | last post by:
I am trying to represent master-detail records from a database The general logic will be populating the first dropdownlist with the master records and on change of the first dropdownlis getting...
4
by: What-a-Tool | last post by:
I am trying to write a program that will take all the members of a data base, add them to a tree, with all child relations as sub-nodes. I am having a problem getting the parent child relations...
6
by: Geoff Jones | last post by:
Hi I have two tables to which I have created a one-to-many relationship. How do I sort the result of the relationship? For example, if one column contains dates, how do I display in the dates...
1
by: Randy Fraser | last post by:
How do I create a relationship on muliple columns in an untyped dataset. Why does this not work. da.Fill(ds) ds.Tables(0).TableName = "DesignSummary" ds.Tables(1).TableName = "FormulaSummary"...
2
by: Joe | last post by:
Hi I have a dataset with 3 tables and 2 relations Is there a way to when I am at 1 row to tell if there is a relation on that row ??? I have the code hardcoded but try to make it work if the #...
2
by: Joe | last post by:
Hi I am going to receive a dataset downstream and I will not know the the fields number of field relations number of relations So I have to be flexible to take unknown data and be able to...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.