Tuesday, November 8, 2011

Programmatically work with SqlDataSource

If you need to create SqlDataSource programmatically you can use this short code snippet:

   DataView newView = new DataView();
            DataSourceSelectArguments args;
            ConnectionStringSettings conStrSet;
            SqlDataSource newViewSqlDataSource;


            args = new DataSourceSelectArguments();
            conStrSet = ConfigurationManager.ConnectionStrings["MyConnectionString"];
            newViewSqlDataSource = new SqlDataSource(conStrSet.ConnectionString, "SELECT * FROM [myTable]");
            newView = (DataView)newViewSqlDataSource.Select(args);

No comments:

Post a Comment