I have a List and there I have stored customerNo from database like this
List
while (readerCus.Read())
{
string[] fields = new string[2];
fields[0] = readerCus["Customer"].ToString();
_customerDetails.Add(fields);
}
Inside a foreach I need to get this "Customer" no one by one and pass it to SQL select statement.
foreach (string[] fields in _customerDetails)
{
string cusId = fields[0];
using (SqlConnection con2 = new SqlConnection(connectionString))
{
con2.Open();
using (SqlCommand command2 = new SqlCommand("SELECT * FROM dbo.Customers WHERE Customer = '" + fields[0].ToString() + "'", con2))
using (SqlDataReader reader2 = command2.ExecuteReader())
{
while (reader2.Read())
{
//My code and here I am generating a token for customer
}
}
}
}
My issue is all the time it runs one time and generate a token.Not continuing and not completing all available customers (say 1000 customers).Any one can point me how can I loop through all customers one by one.
Thank
RD DesignPosted Feb 23, 2015, 11:09 PM
RD DesignPosted Feb 23, 2015, 6:16 AM
while (reader2.Read())
{
TokenCheck check = new TokenCheck();
check.CusTokenNumber = reader2["TokenNo"].ToString();
reader2.Close();
command2.Dispose();
con2.Close();
lblTokenNumber.Text = check.CusTokenNumber;
//Here I am calling a PDF generating method to generate the PDF based on token
getGeneratedPDF();
}
rajat kumarPosted Feb 23, 2015, 6:07 AM