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
Sam HobbsPosted Mar 3, 2010, 4:49 PM
Bryian TanPosted Mar 3, 2010, 3:56 PM
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