By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,651 Members | 1,694 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,651 IT Pros & Developers. It's quick & easy.

Saving matrix in access 2003

P: 12
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....
Feb 9 '08 #1
Share this Question
Share on Google+
11 Replies


ADezii
Expert 5K+
P: 8,607
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?
Feb 9 '08 #2

P: 12
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...
Feb 9 '08 #3

ADezii
Expert 5K+
P: 8,607
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.
Feb 10 '08 #4

P: 12
thanks..and yep..being patient...reply soon!!
Feb 10 '08 #5

ADezii
Expert 5K+
P: 8,607
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.
Expand|Select|Wrap|Line Numbers
  1. 'In General Declarations Section of Form's Code Module
  2. Option Compare Database
  3. Option Explicit
  4. Private aBytePixelPos(15, 15) As Byte
  5.  
  1. To Save sample 2-Dimensional Bytye Array data to a Table:
    Expand|Select|Wrap|Line Numbers
    1. 'Private aBytePixelPos(15, 15) As Byte declared in Form Module
    2. Dim intCounter_1 As Integer
    3. Dim intCounter_2 As Integer, MyDB As DAO.Database, rstPixelVals As DAO.Recordset
    4.  
    5. Set MyDB = CurrentDb()
    6. Set rstPixelVals = MyDB.OpenRecordset("tblPixelValues", dbOpenDynaset)
    7.  
    8. 'Delete any previous Records in tblPixelValues
    9. CurrentDb.Execute "Delete * From tblPixelValues", dbFailOnError
    10.  
    11. Randomize       'Seed the Random Number Generator
    12.  
    13. 'Fill the 2-Dimensional Array (Matrix) with 256 Byte values
    14. For intCounter_1 = LBound(aBytePixelPos) To UBound(aBytePixelPos)
    15.   For intCounter_2 = LBound(aBytePixelPos) To UBound(aBytePixelPos)
    16.     aBytePixelPos(intCounter_1, intCounter_2) = Int(Rnd() * 256)
    17.   Next intCounter_2
    18. Next intCounter_1
    19.  
    20. 'Now that the Array is populated, let's add the Values to tblPixelValues in
    21. 'Row1..Col1,,Col2..Col3..Col4 fashion up to Column16, then new Row..Repeat
    22. For intCounter_1 = LBound(aBytePixelPos) To UBound(aBytePixelPos)   'Rows
    23.   rstPixelVals.AddNew
    24.     For intCounter_2 = LBound(aBytePixelPos) To UBound(aBytePixelPos)   'Columns
    25.       Select Case intCounter_2      'Populate the appropriate Column
    26.         Case 0
    27.           rstPixelVals![Field1] = aBytePixelPos(intCounter_1, intCounter_2)
    28.         Case 1
    29.           rstPixelVals![Field2] = aBytePixelPos(intCounter_1, intCounter_2)
    30.         Case 2
    31.           rstPixelVals![Field3] = aBytePixelPos(intCounter_1, intCounter_2)
    32.         Case 3
    33.           rstPixelVals![Field4] = aBytePixelPos(intCounter_1, intCounter_2)
    34.         Case 4
    35.           rstPixelVals![Field5] = aBytePixelPos(intCounter_1, intCounter_2)
    36.         Case 5
    37.           rstPixelVals![Field6] = aBytePixelPos(intCounter_1, intCounter_2)
    38.         Case 6
    39.           rstPixelVals![Field7] = aBytePixelPos(intCounter_1, intCounter_2)
    40.         Case 7
    41.           rstPixelVals![Field8] = aBytePixelPos(intCounter_1, intCounter_2)
    42.         Case 8
    43.           rstPixelVals![Field9] = aBytePixelPos(intCounter_1, intCounter_2)
    44.         Case 9
    45.           rstPixelVals![Field10] = aBytePixelPos(intCounter_1, intCounter_2)
    46.         Case 10
    47.           rstPixelVals![Field11] = aBytePixelPos(intCounter_1, intCounter_2)
    48.         Case 11
    49.           rstPixelVals![Field12] = aBytePixelPos(intCounter_1, intCounter_2)
    50.         Case 12
    51.           rstPixelVals![Field13] = aBytePixelPos(intCounter_1, intCounter_2)
    52.         Case 13
    53.           rstPixelVals![Field14] = aBytePixelPos(intCounter_1, intCounter_2)
    54.         Case 14
    55.           rstPixelVals![Field15] = aBytePixelPos(intCounter_1, intCounter_2)
    56.         Case 15
    57.           rstPixelVals![Field16] = aBytePixelPos(intCounter_1, intCounter_2)
    58.         Case Else
    59.       End Select
    60.     Next intCounter_2
    61.   rstPixelVals.Update
    62. Next intCounter_1
    63.  
    64. rstPixelVals.Close
    65. Set rstPixelVals = Nothing
    66.  
    67. 'See the results
    68. DoCmd.OpenTable "tblPixelValues", acViewNormal, acReadOnly
    69. DoCmd.Maximize
    70.  
  2. To retrieve Table Data into a 2-Dimensional Array (Variant):
    Expand|Select|Wrap|Line Numbers
    1. Dim MyDB As DAO.Database, rstPixelVals As DAO.Recordset
    2. Dim aVarPixelVals As Variant, intRecord As Integer
    3. 'Dim aByteRetrieveArray(15, 15) As Byte
    4.  
    5.  
    6. Set MyDB = CurrentDb()
    7. Set rstPixelVals = MyDB.OpenRecordset("tblPixelValues", dbOpenDynaset)
    8.  
    9.  
    10. 'aVarPixelVals (a Variant Array) now holds all 256 Table Values
    11. aVarPixelVals = rstPixelVals.GetRows(DCount("*", "tblPixelValues"))
    12.  
    13. 'To retrieve all 256 Values in aVarPixelVals, The first subscript identifies
    14. 'the Field (0 to 15),and the second identifies the Row number (intRecord).
    15. For intRecord = 0 To UBound(aVarPixelVals, 2)       'Row Counters
    16.   Debug.Print aVarPixelVals(0, intRecord) & ", " & aVarPixelVals(1, intRecord) & ", " & _
    17.   aVarPixelVals(2, intRecord) & ", " & aVarPixelVals(3, intRecord) & ", " & _
    18.   aVarPixelVals(4, intRecord) & ", " & aVarPixelVals(5, intRecord) & ", " & _
    19.   aVarPixelVals(6, intRecord) & ", " & aVarPixelVals(7, intRecord) & ", " & _
    20.   aVarPixelVals(8, intRecord) & ", " & aVarPixelVals(9, intRecord) & ", " & _
    21.   aVarPixelVals(10, intRecord) & ", " & aVarPixelVals(11, intRecord) & ", " & _
    22.   aVarPixelVals(12, intRecord) & ", " & aVarPixelVals(13, intRecord) & ", " & _
    23.   aVarPixelVals(14, intRecord) & ", " & aVarPixelVals(15, intRecord)
    24. Next intRecord
    25.  
    26. 'P.S. - If you're not happy storing the values in a Variant, Sub-Type Array, you cal always populate
    27. 'aconventional 2-Dimensional Array, but why the extra work unless it is absolutely required?
Feb 10 '08 #6

P: 12
Thanks a TONNE for the reply....yeah, u guessed it right..."gr8 hurry"..hehe..well, 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!!
Feb 10 '08 #7

P: 12
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...
Feb 10 '08 #8

ADezii
Expert 5K+
P: 8,607
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:
Expand|Select|Wrap|Line Numbers
  1. 'Private aBytePixelPos(15, 15) As Byte declared in Form Module
  2. Dim intCounter_1 As Integer
  3. Dim intCounter_2 As Integer, MyDB As DAO.Database, rstPixelVals As DAO.Recordset
  4.  
  5. Set MyDB = CurrentDb()
  6. Set rstPixelVals = MyDB.OpenRecordset("tblPixelValues", dbOpenDynaset)
  7.  
  8. 'Delete any previous Records in tblPixelValues
  9. CurrentDb.Execute "Delete * From tblPixelValues", dbFailOnError
  10.  
  11. Randomize       'Seed the Random Number Generator
  12.  
  13. 'Fill the 2-Dimensional Array (Matrix) with 256 Byte values
  14. For intCounter_1 = LBound(aBytePixelPos) To UBound(aBytePixelPos)
  15.   For intCounter_2 = LBound(aBytePixelPos) To UBound(aBytePixelPos)
  16.     aBytePixelPos(intCounter_1, intCounter_2) = Int(Rnd() * 255)
  17.   Next intCounter_2
  18. Next intCounter_1
  19.  
  20. 'Now that the Array is populated, let's add the Values to tblPixelValues in
  21. 'Row1..Col1,,Col2..Col3..Col4 fashion up to Column16, then new Row..Repeat
  22. For intCounter_1 = LBound(aBytePixelPos) To UBound(aBytePixelPos)   'Rows
  23.   rstPixelVals.AddNew
  24.     For intCounter_2 = LBound(aBytePixelPos) To UBound(aBytePixelPos)   'Columns
  25.       rstPixelVals.Fields(intCounter_2) = aBytePixelPos(intCounter_1, intCounter_2)
  26.     Next intCounter_2
  27.   rstPixelVals.Update
  28. Next intCounter_1
  29.  
  30. rstPixelVals.Close
  31. Set rstPixelVals = Nothing
  32.  
  33. 'See the results
  34. DoCmd.OpenTable "tblPixelValues", acViewNormal, acReadOnly
  35. DoCmd.Maximize
Feb 11 '08 #9

NeoPa
Expert Mod 15k+
P: 31,263
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.
Feb 11 '08 #10

P: 12
I wud like to thank ADezii for ur effort in solving my problem...thanks 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:
Expand|Select|Wrap|Line Numbers
  1. try
  2.             {
  3.  
  4.                 String Query;
  5.                 OleDbConnection myconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Documents and Settings\tonmoy\Desktop\db1.mdb");
  6.                 OleDbDataReader myreader;
  7.                 OleDbCommand mycommand;
  8.  
  9.  
  10.                 myconn.Open();
  11.                 byte test;
  12.                 int K = 1;
  13.                 for (int i = 0; i < 12; i++)
  14.                 {
  15.  
  16.                         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] + " )";
  17.                         mycommand = new OleDbCommand(Query, myconn);
  18.                         myreader = mycommand.ExecuteReader();
  19.                         myreader.Close();
  20.  
  21.                 }
  22.                 myconn.Close();
  23.             }
  24.             catch(OleDbException e1)
  25.             {
  26.  
  27.                 MessageBox.Show(e1.Errors[0].Message);
  28.  
  29.             }
  30.  
  31.  
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..
Feb 11 '08 #11

NeoPa
Expert Mod 15k+
P: 31,263
Thanks for posting your work here, and recognising ADezii's efforts.
Good luck in the rest of your project and Welcome to TheScripts :)
Feb 11 '08 #12

Post your reply

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