Paolo Duhaylungsod Paolo Duhaylungsod - 2 years ago 114
SQL Question

Add column values to reader

i want to store all of my ID values from sql database to a reader.

so far i got :

string strConnString = "Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True";
string str;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
SqlConnection con = new SqlConnection(strConnString);

str = "select * from CustomerDetails Where CustomerName = '"+Session["New"].ToString()+"'";
com = new SqlCommand(str, con);
SqlDataReader reader = com.ExecuteReader();

while (reader.Read())

Got an error in ListofId, what am i missing or need to declare perhaps?
thank you

enter image description here

Answer Source

if list of id is string then u can use List<string> if int List<int>

List<string> Listofids =  new List<string>(); 
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
    Listofids .Add(reader["Id"].ToString());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download