string connectionstring = "Server=(local);initial catalog=Test;Trusted_Connection=True";
SqlConnection sqlConnection = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
DataSet ds = new DataSet();
cmd.CommandText = "select * from Empdetails";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection;
sqlConnection.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
System.IO.StreamWriter sw_In = new System.IO.StreamWriter(@"C:\Users\God\Desktop\DataDump\IN_Excel.xls");
System.IO.StreamWriter sw_Out = new System.IO.StreamWriter(@"C:\Users\God\Desktop\DataDump\OUT_Excel.xls");
if (reader.Read())
{
string status = reader[6].ToString();
if (status == "1") ;
{
for (int i = 0; i < reader.FieldCount; i++)
{
sw_In.AutoFlush = true;
sw_In.Write(reader[i].ToString() + "\t");
}
sw_In.Write("\n");
}
if (status == "2") ;
{
for (int i = 0; i < reader.FieldCount; i++)
{
sw_Out.AutoFlush = true;
sw_Out.Write(reader[i].ToString() + "\t");
}
sw_Out.Write("\n");
}
}
}
sqlConnection.Close();
In database record as follows
ID Name Address City Phone Actvie ShiftType
1 Ajay LakeViewRaod Chennai 24851524 A 1
2 Suresh GandhiNagar Chennai 24745734 A 1
3 Vimal BoagRoad Chennai 24754874 A 1
4 Rahul Alwarthirunagar Chennai 24758471 A 2
5 Karthik GNTCheetyRoad Chennai 24845454 A 2
6 Naresh Road Chennai 21221211 A 2
But when i run the above code in excel only first row record only displayed as follows
D Name Address City Phone Actvie ShiftType
1 Ajay LakeViewRaod Chennai 24851524 A 1
what is the mistake in my above code