Saving matrix in access 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DeathFrag
    New Member
    • Feb 2008
    • 12

    Saving matrix in access 2003

    hi..
    i've this 2D array of size a[15,15] which i want to store into MS Access 2003 for further processing on the matrix n future use.
    Since there is no built in data type in Access as 'array' or 'matrix' or '2D array'....can anyone help!!!
    Thanking you all in advance...
    waiting for a fast response....
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by DeathFrag
    hi..
    i've this 2D array of size a[15,15] which i want to store into MS Access 2003 for further processing on the matrix n future use.
    Since there is no built in data type in Access as 'array' or 'matrix' or '2D array'....can anyone help!!!
    Thanking you all in advance...
    waiting for a fast response....
    You could easily populate a Table with the data contained in the 2 Dimensional Array in order to 'Persist' the data. It would then be a relatively simple matter to use the GetRows() Method which will return a 2 Dimensional Array from a Recordset based on the Table. This would be your retrieval Method. BTW, what is the Data Type of the Array Elements and what does it represent? a(15, 15) would current hold 256 members since Arrays are indexed at 0, is this your intention?

    Comment

    • DeathFrag
      New Member
      • Feb 2008
      • 12

      #3
      Originally posted by ADezii
      You could easily populate a Table with the data contained in the 2 Dimensional Array in order to 'Persist' the data. It would then be a relatively simple matter to use the GetRows() Method which will return a 2 Dimensional Array from a Recordset based on the Table. This would be your retrieval Method. BTW, what is the Data Type of the Array Elements and what does it represent? a(15, 15) would current hold 256 members since Arrays are indexed at 0, is this your intention?
      I didn't get ur reply...yes, ur rite i've a 15 x 15 2D array consisting of byte values...i.e 256 byte values.
      See i've this array on visual studio 2005, doing my pogramming on images in C#,. What i've done till now is to extract the pixel values of a 15x15 window. Now the next thing i want to do is to store that array in MS Access so that i can work on them and apply other functions on them.

      So my main problem is to store the matrix into MS Access, I've esablished the connection...so can u elaborate how an i store the values...rite from scratch. It will be very helpful of you....and after storing how do i access the array elements ....
      Thanking you...

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by DeathFrag
        I didn't get ur reply...yes, ur rite i've a 15 x 15 2D array consisting of byte values...i.e 256 byte values.
        See i've this array on visual studio 2005, doing my pogramming on images in C#,. What i've done till now is to extract the pixel values of a 15x15 window. Now the next thing i want to do is to store that array in MS Access so that i can work on them and apply other functions on them.

        So my main problem is to store the matrix into MS Access, I've esablished the connection...so can u elaborate how an i store the values...rite from scratch. It will be very helpful of you....and after storing how do i access the array elements ....
        Thanking you...
        I'll see what I can come up with, but please be patient since I am very busy at the moment.

        Comment

        • DeathFrag
          New Member
          • Feb 2008
          • 12

          #5
          thanks..and yep..being patient...reply soon!!

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by DeathFrag
            thanks..and yep..being patient...reply soon!!
            You seem to be in a 'great hurry', so I'll post what I have so far, and I'm sure the rest you can handle. Download my Test Database, and customize it to suit your specific needs. It is fully functional in its current state.
            [CODE=vb]
            'In General Declarations Section of Form's Code Module
            Option Compare Database
            Option Explicit
            Private aBytePixelPos(1 5, 15) As Byte
            [/CODE]
            1. To Save sample 2-Dimensional Bytye Array data to a Table:
              Code:
              'Private aBytePixelPos(15, 15) As Byte declared in Form Module
              Dim intCounter_1 As Integer
              Dim intCounter_2 As Integer, MyDB As DAO.Database, rstPixelVals As DAO.Recordset
              
              Set MyDB = CurrentDb()
              Set rstPixelVals = MyDB.OpenRecordset("tblPixelValues", dbOpenDynaset)
              
              'Delete any previous Records in tblPixelValues
              CurrentDb.Execute "Delete * From tblPixelValues", dbFailOnError
              
              Randomize       'Seed the Random Number Generator
              
              'Fill the 2-Dimensional Array (Matrix) with 256 Byte values
              For intCounter_1 = LBound(aBytePixelPos) To UBound(aBytePixelPos)
                For intCounter_2 = LBound(aBytePixelPos) To UBound(aBytePixelPos)
                  aBytePixelPos(intCounter_1, intCounter_2) = Int(Rnd() * 256)
                Next intCounter_2
              Next intCounter_1
              
              'Now that the Array is populated, let's add the Values to tblPixelValues in
              'Row1..Col1,,Col2..Col3..Col4 fashion up to Column16, then new Row..Repeat
              For intCounter_1 = LBound(aBytePixelPos) To UBound(aBytePixelPos)   'Rows
                rstPixelVals.AddNew
                  For intCounter_2 = LBound(aBytePixelPos) To UBound(aBytePixelPos)   'Columns
                    Select Case intCounter_2      'Populate the appropriate Column
                      Case 0
                        rstPixelVals![Field1] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 1
                        rstPixelVals![Field2] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 2
                        rstPixelVals![Field3] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 3
                        rstPixelVals![Field4] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 4
                        rstPixelVals![Field5] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 5
                        rstPixelVals![Field6] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 6
                        rstPixelVals![Field7] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 7
                        rstPixelVals![Field8] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 8
                        rstPixelVals![Field9] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 9
                        rstPixelVals![Field10] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 10
                        rstPixelVals![Field11] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 11
                        rstPixelVals![Field12] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 12
                        rstPixelVals![Field13] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 13
                        rstPixelVals![Field14] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 14
                        rstPixelVals![Field15] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case 15
                        rstPixelVals![Field16] = aBytePixelPos(intCounter_1, intCounter_2)
                      Case Else
                    End Select
                  Next intCounter_2
                rstPixelVals.Update
              Next intCounter_1
              
              rstPixelVals.Close
              Set rstPixelVals = Nothing
              
              'See the results
              DoCmd.OpenTable "tblPixelValues", acViewNormal, acReadOnly
              DoCmd.Maximize
            2. To retrieve Table Data into a 2-Dimensional Array (Variant):
              [CODE=vb]
              Dim MyDB As DAO.Database, rstPixelVals As DAO.Recordset
              Dim aVarPixelVals As Variant, intRecord As Integer
              'Dim aByteRetrieveAr ray(15, 15) As Byte


              Set MyDB = CurrentDb()
              Set rstPixelVals = MyDB.OpenRecord set("tblPixelVa lues", dbOpenDynaset)


              'aVarPixelVals (a Variant Array) now holds all 256 Table Values
              aVarPixelVals = rstPixelVals.Ge tRows(DCount("* ", "tblPixelValues "))

              'To retrieve all 256 Values in aVarPixelVals, The first subscript identifies
              'the Field (0 to 15),and the second identifies the Row number (intRecord).
              For intRecord = 0 To UBound(aVarPixe lVals, 2) 'Row Counters
              Debug.Print aVarPixelVals(0 , intRecord) & ", " & aVarPixelVals(1 , intRecord) & ", " & _
              aVarPixelVals(2 , intRecord) & ", " & aVarPixelVals(3 , intRecord) & ", " & _
              aVarPixelVals(4 , intRecord) & ", " & aVarPixelVals(5 , intRecord) & ", " & _
              aVarPixelVals(6 , intRecord) & ", " & aVarPixelVals(7 , intRecord) & ", " & _
              aVarPixelVals(8 , intRecord) & ", " & aVarPixelVals(9 , intRecord) & ", " & _
              aVarPixelVals(1 0, intRecord) & ", " & aVarPixelVals(1 1, intRecord) & ", " & _
              aVarPixelVals(1 2, intRecord) & ", " & aVarPixelVals(1 3, intRecord) & ", " & _
              aVarPixelVals(1 4, intRecord) & ", " & aVarPixelVals(1 5, intRecord)
              Next intRecord

              'P.S. - If you're not happy storing the values in a Variant, Sub-Type Array, you cal always populate
              'aconventional 2-Dimensional Array, but why the extra work unless it is absolutely required?[/CODE]

            Comment

            • DeathFrag
              New Member
              • Feb 2008
              • 12

              #7
              Thanks a TONNE for the reply....yeah, u guessed it right..."gr8 hurry"..hehe..w ell, i shall try with the database u attached with ur prev post. I'm wondering if there's any easier way to store a matrix of 256 values(15x15) in any other form( like XML,or any other persistant data storage technique) which will be easier than Accsss?
              Can i store the whole 256 values into an Excel sheet and store that Excel Sheet into Access as an OLE object. But in that case i'm stuck on how to enter the values from Visual Studio 2005 to Excel. And then to retrieve the info back to Visual Studio!!!
              Please help...!!!
              Thanking you in advance!!

              Comment

              • DeathFrag
                New Member
                • Feb 2008
                • 12

                #8
                I went through the VBA code that u provided and tried to work out but as am completely alien to VBA( i know VB and C#) i cudn't understand all wht u've wrote.
                The necessary steps i need t do is like:
                1) Establish the connection between Visual Studio c#.NET and MS Access( which i've done)
                2) Create a table in Access with 256 cells( which i've done)
                3) Then populate the array in Visual Studio (which i've done)
                4) Then insert the values of my array into the table in Access( help!!!)
                5) Then once inserted, retrieve the values back to Visual Studio.(help!!)


                Thanks for the help...

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Originally posted by DeathFrag
                  I went through the VBA code that u provided and tried to work out but as am completely alien to VBA( i know VB and C#) i cudn't understand all wht u've wrote.
                  The necessary steps i need t do is like:
                  1) Establish the connection between Visual Studio c#.NET and MS Access( which i've done)
                  2) Create a table in Access with 256 cells( which i've done)
                  3) Then populate the array in Visual Studio (which i've done)
                  4) Then insert the values of my array into the table in Access( help!!!)
                  5) Then once inserted, retrieve the values back to Visual Studio.(help!!)


                  Thanks for the help...
                  as am completely alien to VBA ( i know VB and C#)
                  If you know VB, you cannot be completely alien to VBA.

                  Then once inserted, retrieve the values back to Visual Studio
                  The retrieval logic is already contained within the Test Database.

                  You already have the 2-Dimensional Array populated in Step #3. To Insert the values into a Table, simply substitute your Array Name for aBytePixelPos in the code below, assuming the same Table name and Field alignment:
                  [CODE=vb]
                  'Private aBytePixelPos(1 5, 15) As Byte declared in Form Module
                  Dim intCounter_1 As Integer
                  Dim intCounter_2 As Integer, MyDB As DAO.Database, rstPixelVals As DAO.Recordset

                  Set MyDB = CurrentDb()
                  Set rstPixelVals = MyDB.OpenRecord set("tblPixelVa lues", dbOpenDynaset)

                  'Delete any previous Records in tblPixelValues
                  CurrentDb.Execu te "Delete * From tblPixelValues" , dbFailOnError

                  Randomize 'Seed the Random Number Generator

                  'Fill the 2-Dimensional Array (Matrix) with 256 Byte values
                  For intCounter_1 = LBound(aBytePix elPos) To UBound(aBytePix elPos)
                  For intCounter_2 = LBound(aBytePix elPos) To UBound(aBytePix elPos)
                  aBytePixelPos(i ntCounter_1, intCounter_2) = Int(Rnd() * 255)
                  Next intCounter_2
                  Next intCounter_1

                  'Now that the Array is populated, let's add the Values to tblPixelValues in
                  'Row1..Col1,,Co l2..Col3..Col4 fashion up to Column16, then new Row..Repeat
                  For intCounter_1 = LBound(aBytePix elPos) To UBound(aBytePix elPos) 'Rows
                  rstPixelVals.Ad dNew
                  For intCounter_2 = LBound(aBytePix elPos) To UBound(aBytePix elPos) 'Columns
                  rstPixelVals.Fi elds(intCounter _2) = aBytePixelPos(i ntCounter_1, intCounter_2)
                  Next intCounter_2
                  rstPixelVals.Up date
                  Next intCounter_1

                  rstPixelVals.Cl ose
                  Set rstPixelVals = Nothing

                  'See the results
                  DoCmd.OpenTable "tblPixelValues ", acViewNormal, acReadOnly
                  DoCmd.Maximize[/CODE]

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32653

                    #10
                    Originally posted by DeathFrag
                    I went through the VBA code that u provided and tried to work out but as am completely alien to VBA( i know VB and C#) i cudn't understand all wht u've wrote.
                    The necessary steps i need t do is like:
                    1) Establish the connection between Visual Studio c#.NET and MS Access( which i've done)
                    2) Create a table in Access with 256 cells( which i've done)
                    3) Then populate the array in Visual Studio (which i've done)
                    4) Then insert the values of my array into the table in Access( help!!!)
                    5) Then once inserted, retrieve the values back to Visual Studio.(help!!)


                    Thanks for the help...
                    DeathFrag,

                    You seem to be having problems with this which are beyond the scope of an Access forum thread. ADezii has gone to great lengths to help you to implement the Access side of this problem, but your attempts to incorporate that into your overall solution is really outside of our remit.

                    It seems that you haven't quite grasped what ADezii was trying to explain (about 16 values in 16 records for instance). There is really little more that he can do for you (beyond the hours of work he's already put in for you).

                    Admin.

                    Comment

                    • DeathFrag
                      New Member
                      • Feb 2008
                      • 12

                      #11
                      I wud like to thank ADezii for ur effort in solving my problem...thank s a lot..yeah ur rite i cant be complete alien to VBA..i fugured out wht u did in that code. I loved it....although i was looking for something simpler and required lesser code.
                      And while going through ur code, something strikd me...wht i did was very simple and wud like to share with you guys: c#.net code snippet:
                      Code:
                      try
                                  {
                      
                                      String Query;
                                      OleDbConnection myconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Documents and Settings\tonmoy\Desktop\db1.mdb");
                                      OleDbDataReader myreader;
                                      OleDbCommand mycommand;
                                      
                      
                                      myconn.Open();
                                      byte test;
                                      int K = 1;
                                      for (int i = 0; i < 12; i++)
                                      {
                                                                            
                                              Query = "insert into table1 values(" + a[i, 0] + "," + a[i, 1] + "," + a[i, 2] + "," + a[i, 3] + "," + a[i, 4] + "," + a[i, 5] + "," + a[i, 6] + "," + a[i, 7] + "," + a[i, 8] + "," + a[i, 9] + "," + a[i, 10] + "," + a[i, 11] + " )";
                                              mycommand = new OleDbCommand(Query, myconn);
                                              myreader = mycommand.ExecuteReader();
                                              myreader.Close();
                                      
                                      }
                                      myconn.Close();
                                  }
                                  catch(OleDbException e1)
                                  {
                                   
                                      MessageBox.Show(e1.Errors[0].Message);
                                    
                                  }
                      The only thing i did( which ironically was very simple n how foolish of me...i asked tht in this forum)..was to create a connection, initilise a dataReader and a datacommand, insert the query into a string and execute it...as i did above..and while storing the values..store them in matrix fashion...with just one loop....man this was simple....
                      Sorry for givingu guys some pain....but i appreciate ur solution and time tht u spent on solvng my problem..Thanks a lot..
                      Looking forward to further assistance in future...
                      Bye..
                      DeathFrag..

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32653

                        #12
                        Thanks for posting your work here, and recognising ADezii's efforts.
                        Good luck in the rest of your project and Welcome to TheScripts :)

                        Comment

                        Working...