471,349 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 software developers and data experts.

Retrieve MS SQL TYPE TEXT into Dataset

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)
Jul 21 '05 #1
1 1732
Luki wrote:
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.StoredProc edure;
cmd.CommandText="sp_columns";
cmd.Parameters.Add("@table_name", "addresses");

da.SelectCommand=cmd;

da.Fill(dsdb);

this.DataGrid1.DataSource=dsdb;
this.DataGrid1.DataBind();
Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jerry Orr | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.