Gridview without using sqldatasource

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mathewgk80
    New Member
    • Sep 2007
    • 103

    #1

    Gridview without using sqldatasource

    Hi all,

    I would like to connect gridview with database without using sql datasource..

    I am using sql server and c#.net..

    Please help me..

    regards,
    Mathew.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    You can create DataSets and DataTables that can be used as the datasource for gridview.
    Create an sql connection
    Create an sql query string (i.e. string myq="SELECT * FROM myTable")
    Create an empty DataTable or DataSet
    Create an sql dataadapter
    use .Fill() of dataadapter to fill datatable/dataset
    Assign the gridview's datasource to the datatable/dataset

    Comment

    • mathewgk80
      New Member
      • Sep 2007
      • 103

      #3
      Originally posted by Plater
      You can create DataSets and DataTables that can be used as the datasource for gridview.
      Create an sql connection
      Create an sql query string (i.e. string myq="SELECT * FROM myTable")
      Create an empty DataTable or DataSet
      Create an sql dataadapter
      use .Fill() of dataadapter to fill datatable/dataset
      Assign the gridview's datasource to the datatable/dataset
      I would like to implement 3 tier also..

      Can you give me an example?

      Comment

      • sijugeo
        New Member
        • Jul 2007
        • 42

        #4
        The three tiers are 1. Presentation Layer,2. Business Layer,3. Databaselayer

        you can write the code for connection to database in the DB layer like this

        string connstring = "Data Source=Database address; Initial Catalog=Databas e; User Id=something; password=someth ing";
        SqlConnection conobj = new SqlConnection(c onnstring);
        SqlDataAdapter da = new SqlDataAdapter( "select * from Employee", conobj);
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;

        In the presentation layer:
        GridView1.DataS ource = bl.gridview();
        GridView1.DataB ind();

        Make the return type of the function as dataset or datatable.

        Then make an object for the dal class. and use it in the BL. Make an object for Bl in the presentation layer and assign it into the gridview..

        Regards,
        Siju.

        Comment

        Working...