Changing the data type of dataadapter?

  • Thread starter Thread starter xlar54
  • Start date Start date
X

xlar54

Given this:

SqlDataAdapter sqlAd = new SqlDataAdapter(sql, sqlCon);

sqlAd.Fill(ds);

I find that the data types that are created are not what I want...
they go by the SQL server data type (which is normally what you would
want). But I need the data to all be represented as strings. Is it
possible to change the data types being "Filled"?

Thanks
 
> SqlDataAdapter sqlAd = new SqlDataAdapter(sql, sqlCon);

sqlAd.Fill(ds);

I find that the data types that are created are not what I want...
they go by the SQL server data type (which is normally what you would
want). But I need the data to all be represented as strings. Is it
possible to change the data types being "Filled"?

One easy way is to modify the sql query so that it converts all fields to
strings before returning them:

string sql = "Select Cast(Field1 as varchar(50)) as f1, ...";
SqlDataAdapter sqlAd = new SqlDataAdapter(sql, sqlCon);
sqlAd.Fill(ds);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top