how to convert sqldatasource to other type like dataview, dataset or datareader
Hi all,
i have got many problems with sqldatasource and dataview
--------------------------------
string ConnectionString = "Server=server;Integrated
Security=True;Database=contest;Persist Security Info=True";
string QueryString = "SELECT * FROM [members]";
System.Web.UI.WebControls.SqlDataSource SqlDataSource = new System.Web.UI.WebControls.SqlDataSource();
SqlDataSource.ConnectionString = ConnectionString;
SqlDataSource.SelectCommand = QueryString;
SqlDataSource.DataSourceMode = System.Web.UI.WebControls.SqlDataSourceMode.DataSet;
DataView dv = new DataView();
dv = (DataView)SqlDataSource;
--------------------------------
CS0030: Cannot convert type 'System.Web.UI.WebControls.SqlDataSource' to 'System.Data.DataView'
--------------------------------
i got similar problems if i use DataSet and DataReader.
SqlDataSource.DataSourceMode = System.Web.UI.WebControls.SqlDataSourceMode.DataSet;
SqlDataSource.DataSourceMode = System.Web.UI.WebControls.SqlDataSourceMode.DataReader;
--------------------------------
thx a lot.To return the DataSet from the SqlDataSource you have to use the SqlDataSource Select method. The Select method will return a DataView if the DataSourceMode of the SqlDataSource is set to System.Web.UI.WebControls.SqlDataSourceMode.DataSet.
If you set the mode to System.Web.UI.WebControls.SqlDataSourceMode.DataReader. A DataReader will be returned.
thx,
but, i dont know how to use sqldatasource as dataview after set it to dataset.
u have an example ?
thx
What is your purpose with the code? Do you only want to access a data source and get a Dataset back? If so I should recommend you to use SqlDataAdaptar:
DataSet ds = new DataSet();using(SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Employees", myConnectionString))
{
adapter.Fill(ds);
}
If you want to use SqlDataSource for some reason, here is an example:
string ConnectionString = "Server=localhost;Integrated Security=True;Database=Northwind;User=****;password=****;";
string QueryString = "SELECT * FROM [Employees]";
System.Web.UI.WebControls.SqlDataSource SqlDataSource = new System.Web.UI.WebControls.SqlDataSource();
SqlDataSource.ConnectionString = ConnectionString;
SqlDataSource.SelectCommand = QueryString;DataSourceSelectArguments arg = new DataSourceSelectArguments();
System.Data.DataView dv = (System.Data.DataView)SqlDataSource.Select(arg);
okay thanks, now continuing on with system.data.dataview dv = ..., how do you retrieve a value, can you finish the code for us?
Many thanks,
Asaf
Here is the thing
DataView dv ;
dv = (DataView)DsOpenOrders.Select(DataSourceSelectArguments.Empty);
dv.Sort = SortField;
return dv;
DsOpenOrders is the SqlDataSource.
THis will help you I guess.
Thanks
Suda
Labels: ado, connectionstring, convert, datareader, dataset, dataview, dataview------string, net, sqldatasource, type
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home