I am using the following code to read from a SELECT
Sql query and then fill my DataTable
from it (dt
is my DataTable, cs
is my connection string and query
is the Sql script):
using (OleDbConnection conn = new OleDbConnection(cs))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(query, conn);
dt.Load(cmd.ExecuteReader());
conn.Close();
}
It works fine and my DataTable
will be filled with what my query returns.
But I want my DataTable
to contain only string
(varchar
) values regardless of what my query says.
E.g. If my query says:
SELECT 1 AS ID, 'John' AS Name
Then the ID value of my Datatable will be an integer whereas I want everything to be string. How can I achieve this?