ds. relations problem with dataset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kjewell23
    New Member
    • Sep 2007
    • 49

    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.SelectC ommand = New OdbcCommand("se lect rmsfiles2.obcop 200.line#, rmsfiles2.obcop 200.ordno, rmsfiles2.obcop 200.quano, rmsfiles2.obcop 200.quana, rmsfiles2.obcop 200.quans, rmsfiles2.obcop 200.c2rdt, rmsfiles2.obcop 200.unitm, rmsfiles2.obcop 200.actsp, rmsfiles2.obcop 200.prdno from rmsfiles2.obcop 200 where ordno = " & Order.ToString( ), myConnection)
    adapter.Fill(ds , "OBCOP200")

    adapter.SelectC ommand = New OdbcCommand("se lect rmsfiles2.mspmp 100.ptyp1, rmsfiles2.mspmp 100.ptyp2, rmsfiles2.mspmp 100.descp, rmsfiles2.mspmp 100.prdno from rmsfiles2.obcop 200 inner join rmsfiles2.mspmp 100 on rmsfiles2.obcop 200.prdno = rmsfiles2.mspmp 100.prdno where rmsfiles2.obcop 200.ordno = " & Order.ToString( ), myConnection)
    adapter.Fill(ds , "MSPMP100")

    ds.Tables(0).Ta bleName = "OBCOP200"
    ds.Tables(1).Ta bleName = "MSPMP100"
    Dim relation As New DataRelation("O BCOP200MSPMP100 ", ds.Tables("OBCO P200").Columns( "prdno"), ds.Tables("MSPM P100").Columns( "prdno"), False)
    ' ds.Relations.Ad d("OBCOP200MSPM P100", ds.Tables("OBCO P200").Columns( "prdno"), ds.Tables("MSPM P100").Columns( "prdno"), True)
    ds.Relations.Ad d(relation)

    gridview1.DataS ource = ds
    gridview1.DataB ind()
    If ds.Tables(0).Ro ws.Count = 0 Then
    lbl_error.Visib le = True
    gridview1.Visib le = False
    Else
    lbl_error.Visib le = False
    gridview1.Visib le = True
    End If

    If ds.Tables(1).Ro ws.Count = 0 Then
    lbl_error.Visib le = True
    gridview1.Visib le = False
    Else
    lbl_error.Visib le = False
    gridview1.Visib le = True
    End If
  • davef
    New Member
    • Sep 2007
    • 98

    #2
    The code looks alright to me. What's the error you're getting again?

    Comment

    • kjewell23
      New Member
      • Sep 2007
      • 49

      #3
      thats the thing I'm not getting no error I'm not getting 3 columns that I need from the table
      Originally posted by davef
      The code looks alright to me. What's the error you're getting again?

      Comment

      • davef
        New Member
        • Sep 2007
        • 98

        #4
        Originally posted by kjewell23
        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?

        Comment

        • kjewell23
          New Member
          • Sep 2007
          • 49

          #5
          There are the ptyp1, ptyp2, and the descp fields that are missing.
          Originally posted by davef
          Which columns are missing from the dataset?

          Comment

          • davef
            New Member
            • Sep 2007
            • 98

            #6
            Originally posted by kjewell23
            There are the ptyp1, ptyp2, and the descp fields that are missing.
            Is your gridview supposed to have hierarchical Master-Detail structure?

            Comment

            • kjewell23
              New Member
              • Sep 2007
              • 49

              #7
              I don't know. Does it
              Originally posted by davef
              Is your gridview supposed to have hierarchical Master-Detail structure?

              Comment

              • davef
                New Member
                • Sep 2007
                • 98

                #8
                Originally posted by kjewell23
                I don't know. Does it
                I could post the code that builds a Master-Detail DataGrid if that would help your problem.

                Comment

                • kjewell23
                  New Member
                  • Sep 2007
                  • 49

                  #9
                  ds.relations problem with dataset

                  Originally posted by davef
                  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
                  Last edited by kjewell23; Sep 27 '07, 07:21 PM. Reason: added something

                  Comment

                  • davef
                    New Member
                    • Sep 2007
                    • 98

                    #10
                    Originally posted by kjewell23
                    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:
                    Code:
                    		private void Form1_Load( object sender, EventArgs e )
                    		{
                    			string szConn = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=server-name";
                    			string szSQL = "select * from dbo.Categories";
                    			SqlConnection conn = new SqlConnection( szConn );
                    			SqlCommand command = new SqlCommand( szSQL );
                    
                    			if( conn.State != ConnectionState.Open )
                    				conn.Open();
                    
                    			command.Connection = conn;
                    			SqlDataAdapter adapter = new SqlDataAdapter( command );
                    			DataSet ds = new DataSet();
                    			adapter.Fill( ds, "Categories" );
                    
                    			szSQL = "select * from Products";
                    			command.CommandText = szSQL;
                    			adapter.Fill( ds, "Products" );
                    
                    			DataRelation relation = new DataRelation(
                    				"CategoryProduct", ds.Tables["Categories"].Columns["CategoryID"],
                    				ds.Tables["Products"].Columns["CategoryID"], true );
                    			ds.Relations.Add( relation );
                    
                    
                    			this.dataGrid1.DataSource = ds;
                    			this.dataGrid1.DataMember = "Categories";
                    			conn.Close();
                    		}

                    Comment

                    • kjewell23
                      New Member
                      • Sep 2007
                      • 49

                      #11
                      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

                      Originally posted by davef
                      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:
                      Code:
                      		private void Form1_Load( object sender, EventArgs e )
                      		{
                      			string szConn = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=server-name";
                      			string szSQL = "select * from dbo.Categories";
                      			SqlConnection conn = new SqlConnection( szConn );
                      			SqlCommand command = new SqlCommand( szSQL );
                      
                      			if( conn.State != ConnectionState.Open )
                      				conn.Open();
                      
                      			command.Connection = conn;
                      			SqlDataAdapter adapter = new SqlDataAdapter( command );
                      			DataSet ds = new DataSet();
                      			adapter.Fill( ds, "Categories" );
                      
                      			szSQL = "select * from Products";
                      			command.CommandText = szSQL;
                      			adapter.Fill( ds, "Products" );
                      
                      			DataRelation relation = new DataRelation(
                      				"CategoryProduct", ds.Tables["Categories"].Columns["CategoryID"],
                      				ds.Tables["Products"].Columns["CategoryID"], true );
                      			ds.Relations.Add( relation );
                      
                      
                      			this.dataGrid1.DataSource = ds;
                      			this.dataGrid1.DataMember = "Categories";
                      			conn.Close();
                      		}

                      Comment

                      • davef
                        New Member
                        • Sep 2007
                        • 98

                        #12
                        Originally posted by kjewell23
                        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.

                        Comment

                        • kjewell23
                          New Member
                          • Sep 2007
                          • 49

                          #13
                          Originally posted by davef
                          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

                          Comment

                          • davef
                            New Member
                            • Sep 2007
                            • 98

                            #14
                            Originally posted by kjewell23
                            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?

                            Comment

                            • kjewell23
                              New Member
                              • Sep 2007
                              • 49

                              #15
                              the fields that im missing is in the second table i tried both tables for the datamember and still missing
                              Originally posted by davef
                              Does your first datatable contain the fields you're missing from the grid now?

                              Comment

                              Working...