none
DataRowBuilder RRS feed

  • Question

  • I have important strategic considerations to use my VFPOLEDB database in C# code. For some operations they are very fast and security is not that important. I have a vast data pool going back many years. Converting it to Sql Server will be a waste of time.

     

    I connected VFP 9 databases to Visual Studio with no problem. I defined a dataset for each database. I did it with the wizard Data==>Add New Data Source, etc. I tried to use the datasets in the code and ran into a problem with DataRowBuilder. I could not find any meaningful information on the subject at all. Some of the posts I found are related to Sql Server not OleDb.

     

    This is my code:

     

    private void Form1_Load( object sender, EventArgs e )

    {

          System.Data.DataRowBuilder rb;

          DataSet1.crossreffirstlevelRow[] crRefRows = new DataSet1.crossreffirstlevelRow( );  // <== error here

          int bb = crRefRows.Length;crRefRows.GetValue ( 0, crRefRows.Length - 1 );   // no error here, it is just a toy. 

     

          foreach (DataSet1.crossreffirstlevelRow rowCrRef in crRefRows)

          {

              string memo1 = "";

              string named = findTextByNumericIDFirst( rowCrRef.pointer_two, out memo1 );

              this.treeView1.Nodes.Add ( rowCrRef.pointer_two );

              if (memo1 != "")

              {

                  this.treeView1.Nodes[ rowCrRef.pointer_two ].Tag = memo1;

                  this.treeView1.Nodes[ rowCrRef.pointer_two ].Name = "| " + named;

              }

              else

             {

                 this.treeView1.Nodes[ rowCrRef.pointer_two ].Name = named;

             }

        }

    } // Form1_Load

     

    I find it strange that the Intellisense never protested when I typed all this code. The databases are very old. I did not remember the column names like "named" and "memo1" or "pointer_two." They were given to me by the Intellisense combobox. At the same time I got an error: there is no overload with 0 arguments. It wants a DataRowBuilder.

     

    The DataRowBuilder is a protected class that is not designed to be used by app programmers. There is no constructor. What can I do about it?

     

    Thanks.

    Wednesday, September 12, 2007 12:59 PM

All replies

  • I kind of don't know where to start with answering this question, but a couple of things come to mind:

    • It's not clear what the code you've posted has to do with the DataRowBuilder.  You've declared an instance of DataRowBuilder, but you're not using it for anything.   
    • I'm not sure what you mean by the column names named and memo1 "were given to me by the Intellisense combobox".  You've explicitly declared memo1 and named as local string variables.  That will make them show up in Intellisense, and should.
    • The line that you've indicated as having an error is, in fact, an error.  The strongly-typed data row constructor returns a single instance; you're trying to assign this to an array.

    At any rate, in ADO.NET you don't add a row to a table by calling the DataRow object's constructor.  You add a row to a table by calling the Add method on the table's Rows collection.  This method wants you to pass it an object[] parameter that contains one element for each column, in the order that the columns appear in the table's Columns collection.

     

    If you're using a typed data set, you can also add a row by calling the table's AddTableNameRow method.  This method is basically a wrapper around the Add(object[]) method that handles type conversion for the individual columns.

     

    The DataRowBuilder class exists because the DataTable classes use it.  The documentation says it's not intended to be used from your code, and they mean it.

    Wednesday, September 12, 2007 9:48 PM
  •  Robert Rossney wrote:

    I kind of don't know where to start with answering this question, but a couple of things come to mind:

    • It's not clear what the code you've posted has to do with the DataRowBuilder.  You've declared an instance of DataRowBuilder, but you're not using it for anything.   
    • I'm not sure what you mean by the column names named and memo1 "were given to me by the Intellisense combobox".  You've explicitly declared memo1 and named as local string variables.  That will make them show up in Intellisense, and should.
    • The line that you've indicated as having an error is, in fact, an error.  The strongly-typed data row constructor returns a single instance; you're trying to assign this to an array.

    At any rate, in ADO.NET you don't add a row to a table by calling the DataRow object's constructor.  You add a row to a table by calling the Add method on the table's Rows collection.  This method wants you to pass it an object[] parameter that contains one element for each column, in the order that the columns appear in the table's Columns collection.

     

    If you're using a typed data set, you can also add a row by calling the table's AddTableNameRow method.  This method is basically a wrapper around the Add(object[]) method that handles type conversion for the individual columns.

     

    The DataRowBuilder class exists because the DataTable classes use it.  The documentation says it's not intended to be used from your code, and they mean it.

     

    Thanks,

     

    The declaration for named and memo1 has nothing to do with the column (field) names. It is just a coincidence. I have a right to use the same name for a string variable as for my column (field) name.

     

    rowCrRef.pointer_two  is case in point. pointer_two (from a different table in the same dataset) is a Type string column and pointer_two is not declared as a string although it may well be in the future. That objection of yours which I appreciate nonetheheless is completely irrelevant.

     

    The DataowBuilder is declared because it is a half backed code. I tried to use db as an argument for the next statement but got an error that I was using an anassigned variablle whcih is correct, it is unassigned.

     

    I think you've shown me a way and I will use it. Most likely it will work.

     

    Thanks much.

    Thursday, September 13, 2007 2:26 PM
  • This is what actually worked for me:

     

    ComeAndGet.DataSet1TableAdapters.crossreffirstlevelTableAdapter TA = new ComeAndGet.DataSet1TableAdapters.crossreffirstlevelTableAdapter ( );

    TA.Fill ( Globals.crossRef1st );

     

     

    where:

     

    public class Globals

    {

         private static ComeAndGet.DataSet1.crossreffirstlevelDataTable crossRef1st_ = new  DataSet1.crossreffirstlevelDataTable ( );

         public static ComeAndGet.DataSet1.crossreffirstlevelDataTable crossRef1st

         {

             get { return crossRef1st_; }

             set { crossRef1st_ = value; }

          }

    }

     

    The tableAdapters fill all the tables in the DataSet1. ComeAndGet is the namespace.

    Friday, September 14, 2007 5:41 PM