473,404 Members | 2,114 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,404 software developers and data experts.

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....
Feb 9 '08 #1
11 2844
ADezii
8,834 Expert 8TB
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
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
8,834 Expert 8TB
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
thanks..and yep..being patient...reply soon!!
Feb 10 '08 #5
ADezii
8,834 Expert 8TB
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
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
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
8,834 Expert 8TB
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
32,556 Expert Mod 16PB
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
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
32,556 Expert Mod 16PB
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

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

Similar topics

6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
13
by: Charulatha Kalluri | last post by:
Hi, I'm implementing a Matrix class, as part of a project. This is the interface I've designed: class Matrix( )
2
by: manning_news | last post by:
Has anyone had a problem with Access 2003 not saving their coding? I've been using 2003 for a couple of months now and just this week noticed that some coding I'd done for a database was not there...
16
by: raj | last post by:
Hi, I saw it mentioned that "int" is the fastest data-type for use in C ,that is data storage/retrieval would be the fastest if I use int among the following 4 situations in a 32 bit machine with...
0
by: Kim Bracknell | last post by:
Hi there, In v 0.6 of Web Matrix, if I add a new database connection using the wizard and choose "Access Database" I get the following error: "Unable to create project. The Microsoft Access...
0
by: Doug | last post by:
Hi I have been working through Scott Mitchell's book on asp.net in 24 hours and found the book very informative - within the web matrix API. However when I try to move those new skills into...
4
by: tt40 | last post by:
Anyone know how to prevent Access 2002 from automatically breaking all the incorrect joins in a query and then automatically saving the broken query? This is what I would call stupid design...
8
by: MVM | last post by:
I am new to VS 2003. I did programming in vb6 and vc6, but not through studio. I am having lot of confusion on how to start, where to start? I like to write a program in vc++ under vs 2003. i...
21
by: =?UTF-8?B?TWFydGluIFDDtnBwaW5n?= | last post by:
Hello, I´m using a very large 2-dimensional double matrix (45.000x45.000) in my program. At the initialization of the matrix: double matrix = new double I am getting an out of memory...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.