How SqlDataSource put in C#?

techques
techques used Ask the Experts™
on
There is a datalist in aspx page:

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="3" RepeatDirection="Horizontal" OnItemDataBound="DataList1_ItemCommand">

Currently, I use

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="select id,col,name,age,width,height from operation">
</asp:SqlDataSource>

to bind the data source in aspx page.

How can I put it to VC#?


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sr. System Analyst
Commented:
Sqlconnection con= new sqlconnection( );
con.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30"
// or ConnectionStrings:ConnectionString , not sure about this
con.open();

sql command cmd =new command("select id,col,name,age,width,height from operation",con);
sqldataadpater da= new dataadpter(cmd);
dataset ds();
da.fill(ds," tablename");

DataList1.datasource="tablename";

con.close();

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial