Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Data Sources in .NET

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 70
    Comment on it

    While fetching data from the sources like the text file , the xml file or from the database first thing you need to do is to create a data source for it.

    Data Source acts like a object of information that holds information about the settings and path that we will use to fetch the data from the selected data source.

    Main work of data source :

    • Managing connection
    • Selecting data
    • Managing presentation aspects like paging, caching, etc.
    • Manipulating data

    The data source controls used for hierarchical data are:

    • XMLDataSource - It allows binding to XML files and strings with or without schema information.

    • SiteMapDataSource - It allows binding to a provider that supplies site map information.

    The SqlDataSource Control

    Mainly used while interacting with the Sql Server database and tables associated to it.

    <asp:SqlDataSource runat="server" ID="MySqlSource"
       ProviderName='<%$ ConnectionStrings:LocalNWind.ProviderName  %>'
       ConnectionString='<%$ ConnectionStrings:LocalNWind %>'
       SelectionCommand= "SELECT * FROM EMPLOYEES" />
    
    <asp:GridView ID="GridView1" runat="server" DataSourceID="MySqlSource" />

     

    The ObjectDataSource Control

    Object data source control is mainly concerned with the data of object kind like the models and entities.

    public class Student
    {
       public int StudentID { get; set; }
       public string Name { get; set; }
       public string City { get; set; }
       
       public Student()
       { }
       
       public DataSet GetStudents()
       {
          DataSet ds = new DataSet();
          DataTable dt = new DataTable("Students");
          
          dt.Columns.Add("StudentID", typeof(System.Int32));
          dt.Columns.Add("StudentName", typeof(System.String));
          dt.Columns.Add("StudentCity", typeof(System.String));
          dt.Rows.Add(new object[] { 1, "M. H. Kabir", "Calcutta" });
          dt.Rows.Add(new object[] { 2, "Ayan J. Sarkar", "Calcutta" });
          ds.Tables.Add(dt);
          
          return ds;
       }
    }
    .net

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: