HI,
If I use this code below
command = new OleDbCommand(SQLQUERY, myconn)
myReader = command.ExecuteReader();
while (myReader.Read())
{
while (i < myReader.FieldCount)
{
value = value + myReader.GetString(i) + "\t ";
i++;
}
listBox1.Items.Add(value);
value = "";
i = 0;
}
Then all the data must be of string value, Is there a option to check the type of value the next value is or must i know this?
Loading

Bryian TanRank #396 · 6.3K reputationPosted Mar 3, 2010, 10:56 AM EST
You can do something like myReader.GetValue(i).GetType().ToString() to print out the type name
or
if (myReader.GetValue(i).GetType() == typeof(DBNull))
Response.Write("null value");
else if (myReader.GetValue(i).GetType() == typeof(int32))
value = value + myReader.GetInt32(i) + "\t ";
else if (myReader.GetValue(i).GetType() == typeof(String))
value = value + myReader.GetString(i) + "\t ";
...
...
or, I think you can use
value = value + myReader.GetValue(i) + "\t ";
Thanks,
Bryian Tan
Sam HobbsRank #107 · 20.5K reputationPosted Mar 3, 2010, 11:49 AM EST