I think the problem is in each record your application overwrite the same pdf file. try to build unique file name like below
string reportFileName =string.Format(@"C:\pdfd\st1_{0}.pdf",st1) ;
or
append timespan to file name.[
^]
You can avoid connection related issues by introducing methods to do the database operations and properly handling database connections in those methods. for example,
public List<string> GetFlionoList()
{
List<string> flionoList = new List<string>();
using(SqlConnection connection = new SqlConnection(yourConnectionString) )
using(SqlCommand cmd = new SqlCommand("select Fliono from BOND_REG where status='A'", connection))
{
connection.Open();
using(SqlDataReader sdr= cmd.ExecuteReader())
{
while (sdr.Read())
{
flionoList.Add(sdr.Getstring(0));
}
}
}
return flionoList;
}
public void UpdateStaus(string fliono)
{
using(SqlConnection connection = new SqlConnection(yourConnectionString) )
using(SqlCommand cmd = new SqlCommand("update BOND_REG set status='P' where fliono='"+fliono+"'", connection))
{
connection.Open();
cmd.ExecuteNonQuery();
}
}
Now you can call
GetFlionoList()
and get the list and iterate each item of the list and call methods like
UpdateStaus
for each item. make sure that you have dispose the connection and readers using
"using blocks"