How to get datas from a cloumn in a database(sql) and store in in array?
hi all,
can any one tell me how to get the datas in a cloumn in a database (SQL) and store them in a array
plz send me the sample code urgent
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Kirtan PatelRank #292 · 8.6K reputationPosted Jun 11, 2009, 12:38 AM EDT
Using System.Data.SqlClient; private void Form1_Load(object sender, EventArgs e) { //Get Count of Records so that we can make array of that member counts SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"); con.Open(); SqlCommand comm = new SqlCommand("select count(*) from users",con); int count = Convert.ToInt32(comm.ExecuteScalar()); string[] x = new string[count]; SqlCommand comm2 = new SqlCommand("select * from users",con); SqlDataReader reader = comm2.ExecuteReader(); //Copy Column Data to Array int i= 0; while (reader.Read()) { x[i] = reader["username"].ToString(); i++; } con.Close(); //Testing The Array for (i = 0; i <= x.Length-1; i++) { listBox1.Items.Add(x[i]); } }