Retrieve MS SQL TYPE TEXT into Dataset

  • Thread starter Thread starter Luki
  • Start date Start date
L

Luki

Hello

i'm stuck on a seemingly small problem. i'm trying get the default value
of a column in a table on a MS SQL Server. i try to use sp_columns. eg
sp_columns @table_name = 'addresses'

in Query Analyzer this will produce a nice list where COLUMN_DEF
contains the default value. but if i fill a dataset with it, the column
COLUMN_DEF is always null! i even binded it to a datagrid and the column
shows up empty.
looking at the SP the column COLUMN_DEF seems to be of type TEXT. so i
guess this is the problem...

any idea on how solve this and get the value in COLUMN_DEF? i would like
to use a system stored procedure, not access the sysobjects directly.

thanks for any pointers!

beat


(i couldn't find any better matching ng. if there's one i'll happily
repost there)
 
Luki said:
Hello

i'm stuck on a seemingly small problem. i'm trying get the default value
of a column in a table on a MS SQL Server. i try to use sp_columns. eg
sp_columns @table_name = 'addresses'

in Query Analyzer this will produce a nice list where COLUMN_DEF
contains the default value. but if i fill a dataset with it, the column
COLUMN_DEF is always null! i even binded it to a datagrid and the column
shows up empty.
looking at the SP the column COLUMN_DEF seems to be of type TEXT. so i
guess this is the problem...

any idea on how solve this and get the value in COLUMN_DEF? i would like
to use a system stored procedure, not access the sysobjects directly.

thanks for any pointers!

beat


(i couldn't find any better matching ng. if there's one i'll happily
repost there)


ok. i just checked this and retrieved a table containing a text field,
the dataset worked perfect. so type TEXT isn't responsible. what the...
here's the code to test:




System.Data.SqlClient.SqlConnection cn=
new System.Data.SqlClient.SqlConnection(cns);
System.Data.SqlClient.SqlCommand cmd=
new System.Data.SqlClient.SqlCommand();
System.Data.SqlClient.SqlDataAdapter da=
new System.Data.SqlClient.SqlDataAdapter();

System.Data.DataSet dsdb=
new System.Data.DataSet();

cmd.Connection=cn;

cmd.CommandType=System.Data.CommandType.StoredProcedure;
cmd.CommandText="sp_columns";
cmd.Parameters.Add("@table_name", "addresses");

da.SelectCommand=cmd;

da.Fill(dsdb);

this.DataGrid1.DataSource=dsdb;
this.DataGrid1.DataBind();
 
Back
Top