CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    [RESOLVED] Database to an Array

    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

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Database to an Array

    Are you trying to store the data read from one field into an array; or more than one field into one array?

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Database to an 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.

  4. #4
    Join Date
    Jul 2007
    Location
    In the present
    Posts
    80

    Re: Database to an Array

    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();;
                    
            }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured