Reputation: 231
This set of codes apparently, is to retrieve the data from the server (from a certain period of days) and to display them in a notepad. Im not sure why, it keeps popping out message box "char", "money" and "nvarchar". Pardon me if its a silly question
SqlCommand objCmd = new SqlCommand("SELECT CONVERT(char(80), InvDate,3) AS InvDate,InvoiceNo,EmployerCode,TaxAmount + SubTotal AS Amount,'' AS Payment FROM Invoice WHERE (InvDate >= CONVERT(datetime, '"+dtpFrom.Text +"', 0 )) AND (InvDate <= CONVERT(datetime, '"+dtpTo.Text+"', 0))", objConn);
SqlDataReader objReader;
objReader = objCmd.ExecuteReader();
System.IO.FileStream fs = new System.IO.FileStream("C:\\CMSExportedData\\Sales-" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt", System.IO.FileMode.Create);
System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.Default);
int count = 0;
while (objReader.Read())
{
for (int i = 0; i < 5; i++)
{
if (!objReader.IsDBNull(i))
{
string s;
s = objReader.GetDataTypeName(i);
MessageBox.Show(s);
if (objReader.GetDataTypeName(i) == "char")
{
sw.Write(objReader.GetString(i));
}
else if (objReader.GetDataTypeName(i) == "datetime")
{
sw.Write(objReader.GetSqlMoney(i).ToString());
}
else if (objReader.GetDataTypeName(i) == "nvarchar")
{
sw.Write(objReader.GetString(i));
}
}
if (i < 4)
{
sw.Write("\t");
}
}
count = count + 1;
sw.WriteLine();
}
sw.Flush();
fs.Close();
objReader.Close();
objConn.Close();
MessageBox.Show(count + " records exported successfully.");
this.Close();
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void dtpTo_ValueChanged(object sender, EventArgs e)
{
}
Upvotes: 0
Views: 1317
Reputation: 5831
Your datasource contains a column of the type Money
. Note that you do not handle the money type.
That is why one of the messageBoxes contains the 'Money' text.
Upvotes: 1
Reputation: 245399
You have a MessageBox
being shown inside the loop which is why you're seeing multiple MessageBox
es with the data types. If you really don't want to see them, just remove the following line:
MessageBox.Show(s);
Upvotes: 4