|
-
July 19th, 2011, 10:29 AM
#1
Table data into Array
I wish to populate an array with the data from a table. How do I do this?
More specifically, I wish to put the data from a specific column, into the array, and later on add all the values in each cell of the array.
I tried searching on google but I guess I'm using the wrong words to search.
-
July 19th, 2011, 10:49 AM
#2
Re: Table data into Array
datareader would be one method.
Always use [code][/code] tags when posting code.
-
July 20th, 2011, 11:33 AM
#3
Re: Table data into Array
DataTable will provide you a Row collection, and each row will contain the fields selected in your query. So you would access a value using:
Code:
string value = dtResults.Rows[0]["FIELDNAME"].ToString();
Code:
DataTable dtResults = new DataTable();
OleDbConnection dbConnection = new OleDbConnection("your connection string");
try
{
dbConnection.Open();
if (dbConnection.State == ConnectionState.Open)
{
OleDbCommand dbCommand = dbConnection.CreateCommand();
dbCommand.CommandType = CommandType.Text;
dbCommand.CommandText = "your query (select * from...)";
OleDbDataReader dbReader = dbCommand.ExecuteReader();
if (dbReader.HasRows)
dtResults.Load(dbReader);
dbReader.Close();
dbConnection.Close();
}
}
catch (Exception ex)
{
throw new Exception("Unable to execute query as requested.", ex);
}
-
July 21st, 2011, 02:06 AM
#4
Re: Table data into Array
Hello
This can also help you, try this
Dim rst As DAO.Recordset
Dim lngNum As Long
Set rst = CurrentDb.Open("TableNameHere")
For 1 to UBound(YourArray)
With rst
.AddNew
!FieldName = YourArray(lngNum)
.Update
End With
lngNum = lngNum + 1
Next
There may be error, not tested, just an overview.
-
July 21st, 2011, 02:09 AM
#5
Re: Table data into Array
Thanks for the effort. But, that code is for VB6. This is the C# Forum. Also, that code uses DAO. In .NET ADO is most common...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|