Hi I am having difficulties finding an example to read data from a database into an array string.
will someone please point me in the correct direction for an example.. Possibly some pseudocode.
I am using .net 4.0
Printable View
Hi I am having difficulties finding an example to read data from a database into an array string.
will someone please point me in the correct direction for an example.. Possibly some pseudocode.
I am using .net 4.0
Are you trying to store the data read from one field into an array; or more than one field into one array?
You'll have to give us far more info than that. first off, how are you accessing your database? If you can access database tables already then reading data into a string should be trivial. If you don;t know how to access a database then you are asking the wrong question and you need to lookup and read through some tutorials.
Here is what I have found that is working
Code:private void GetNameArray()
{
myconnection.Open();
SQLiteCommand cmd = new SQLiteCommand("Select a_name from agent ORDER BY a_name ASC", myconnection);
//DataTable dt_group = new DataTable();
SQLiteDataAdapter adaptor = new SQLiteDataAdapter(cmd);
DataSet nameDataSet = new DataSet("nameArray");
adaptor.Fill(nameDataSet,"nameArray");
string[] myListArray = new string[nameDataSet.Tables[0].Rows.Count];
foreach(DataRow row in nameDataSet.Tables[0].Rows)
{
myListArray[j] = row["a_name"].ToString();
j++;
}
name = myListArray;
//dbClose();
myconnection.Close();;
}