Get a single value from SQLDataSource

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Hi

I am using .NET 2 with c# and want to retrieve a single value from my
stored procedure.

I currently have the following code:

---------------------------------------------------------------------------------------------------------------------------------
ConnectionStringSettings connectionSettings =
ConfigurationManager.ConnectionStrings["ConnectionString"];

SqlDataSource ds = new SqlDataSource();

ds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
ds.SelectCommand = "GetCustomerName";

ds.SelectParameters.Add("traderId", TypeCode.Int32, "1");

ds.Select();
---------------------------------------------------------------------------------------------------------------------------------

Obviously this won't get my customer name :(

How do I get the actual value?

Thanks!
 
Will this of any help?
http://msdn2.microsoft.com/en-us/library/37hwc7kt.aspx

Hi

I am using .NET 2 with c# and want to retrieve a single value from my
stored procedure.

I currently have the following code:

---------------------------------------------------------------------------------------------------------------------------------
ConnectionStringSettings connectionSettings =
ConfigurationManager.ConnectionStrings["ConnectionString"];

SqlDataSource ds = new SqlDataSource();

ds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
ds.SelectCommand = "GetCustomerName";

ds.SelectParameters.Add("traderId", TypeCode.Int32, "1");

ds.Select();
---------------------------------------------------------------------------------------------------------------------------------

Obviously this won't get my customer name :(

How do I get the actual value?

Thanks!
 
Yeah that is how I have always done it.

Just curious if it can be done with the SQLDataSource?
 
Yes. Set the SqlDataSource's ConnectionString, SelectCommand (&
SelectParameters if required) and call the Select method. Assuming
SqlDataSource.DataSourceMode is set DataSet, returnedDataView[0][0] should
give the first column of the first row from the stored proc.

DataView returnedDataView= (DataView)ds.Select();

Is this what your looking for?

Yeah that is how I have always done it.

Just curious if it can be done with the SQLDataSource?
 
Back
Top