1

I'm struggling a bit with this. I want to get the list of ids from the database where a certain value is equal to a certain value in the row. This call will likely return multiple ids. I want to store the value in the ids returned in a list or arraylist in the c# code but I am finding this troublesome. I have the code up to here:

 string strConnection = ConfigurationSettings.AppSettings["ConnectionString"];
 MySqlConnection connection = new MySqlConnection(strConnection);
 MySqlCommand command = connection.CreateCommand();
 MySqlDataReader reader;
 command.CommandText = "SELECT idprojects FROM `test`.`projects` WHERE application_layers = " + applicationTiers + "";
 connection.Open();
 reader = command.ExecuteReader();

Any help would be much appreciated

asked May 29, 2011 at 11:08

1 Answer 1

2
 string strConnection = ConfigurationSettings.AppSettings["ConnectionString"];
 MySqlConnection connection = new MySqlConnection(strConnection);
 List<string> array = new List<string>();
 using (MySqlCommand cmd = new MySqlCommand("SELECT idprojects FROM `test`.`projects` WHERE application_layers = " + applicationTiers, connection))
 {
 try
 {
 using (MySqlDataReader Reader = cmd.ExecuteReader())
 {
 while (Reader.Read())
 {
 array.Add(Reader["idprojects"].ToString());
 }
 }
 }
 catch (Exception ex)
 {
 throw;
 }
 }
 string[] ret= array.ToArray();
answered May 29, 2011 at 11:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.