Click here to Skip to main content
12,511,307 members (109,533 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB Visual-Studio VB.NET
Hi all,

How to fill data into datagridview?i already fill the data into dataset where I name it dsReport.xsd and I want to build another sub that view all data that grab from dataset. How should I code that without declaring again the string connection? And I grab the database data using datareader where I'm not using any data adapter because I have a problem with it..

dgvReport = datagridview
dsReport = dataset
TblCashDetails = cash table

Anyone can help me?
Posted 2-Nov-11 21:27pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

public void PopulateGrid(GridView grdView, string sqlQuery, Page form)
    {
        try
        {
            adp = new SqlDataAdapter(sqlQuery, conn);
            tbl = new DataTable();
            adp.Fill(tbl);
            grdView.DataSource = tbl;
            grdView.DataBind();
        }
        catch (Exception ex)
        {
            MsgBox("Populate GridView Error: " + ex.Message, form);
        }
    }
 
    public void PopulateGrid(DataGrid dtGrd, string sqlQuery, Page form)
    {
        try
        {
            adp = new SqlDataAdapter(sqlQuery, conn);
            tbl = new DataTable();
            adp.Fill(tbl);
            dtGrd.DataSource = tbl;
            dtGrd.DataBind();
        }
        catch (Exception ex)
        {
            MsgBox("Populate DataGrid Error: " + ex.Message, form);
        }
    }
 
    public void PopulateGrid(DataList dtLst, string sqlQuery, Page form)
    {
        try
        {
            adp = new SqlDataAdapter(sqlQuery, conn);
            tbl = new DataTable();
            adp.Fill(tbl);
            dtLst.DataSource = tbl;
            dtLst.DataBind();
        }
        catch (Exception ex)
        {
            MsgBox("Populate DataList Error: " + ex.Message, form);
        }
    }
  Permalink  
Comments
Fadhli Azmin 3-Nov-11 4:16am
   
Is this will view all data that store in dataset?or it need to loop to find every details to be viewed?anyway, thanks for the code..
biswarup88 3-Nov-11 5:06am
   
Above methods help to Populate grid for GridView , DataGrid as well as DataList

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160929.1 | Last Updated 3 Nov 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100