G
G-Oker
Guest
Hello,
I am reading data from an SQL command, and saving this output into a file.
What I would like to do is , if the column field is empty, to replace with with "no data"
The data I get back is in this format
and the code I am currently using is
using (SqlCommand cmd = new SqlCommand("select [guest_name],from MyTableName", connection))
{
using (SqlDataReader reader = cmd.ExecuteReader())
using (StreamWriter writer = new StreamWriter(output1))
{
while (reader.Read())
{
writer.WriteLine(reader[0].ToString() +","+ reader[1].ToString());
}
}
SqlCommand dropTable = new SqlCommand("drop table reviewProTemp", connection);
dropTable.ExecuteNonQuery();
}
connection.Close();
what I am having trouble figuring out is (please excuse the pseudo code) , and was wondering if someone could help ?
if (reader[1] = NULL || reader[1] == "")
{
reader[1] = "no data"
}
But, I know this wont work but hopefully you get the idea as to what I am trying to achieve
Thanks
[url="https://social.msdn.microsoft.com/Forums/en-US/5106a6ff-94de-43ac-8fc1-555fc86a9138/c-sqldatareader-replace-empty-column-field-reader-data-with-text?forum=csharpgeneral"]Continue reading...[/url]
I am reading data from an SQL command, and saving this output into a file.
What I would like to do is , if the column field is empty, to replace with with "no data"
The data I get back is in this format
and the code I am currently using is
using (SqlCommand cmd = new SqlCommand("select [guest_name],from MyTableName", connection))
{
using (SqlDataReader reader = cmd.ExecuteReader())
using (StreamWriter writer = new StreamWriter(output1))
{
while (reader.Read())
{
writer.WriteLine(reader[0].ToString() +","+ reader[1].ToString());
}
}
SqlCommand dropTable = new SqlCommand("drop table reviewProTemp", connection);
dropTable.ExecuteNonQuery();
}
connection.Close();
what I am having trouble figuring out is (please excuse the pseudo code) , and was wondering if someone could help ?
if (reader[1] = NULL || reader[1] == "")
{
reader[1] = "no data"
}
But, I know this wont work but hopefully you get the idea as to what I am trying to achieve
Thanks
[url="https://social.msdn.microsoft.com/Forums/en-US/5106a6ff-94de-43ac-8fc1-555fc86a9138/c-sqldatareader-replace-empty-column-field-reader-data-with-text?forum=csharpgeneral"]Continue reading...[/url]