问题描述
大家好,
如何将数据填充到datagridview中?我已经将数据填充到数据集中,我将其命名为dsReport.xsd,我想构建另一个子视图来查看从数据集中获取的所有数据.如何在不再次声明字符串连接的情况下进行编码?而且我使用datareader来获取数据库数据,在这里我不使用任何数据适配器,因为我有问题..
dgvReport = datagridview
dsReport =数据集
TblCashDetails =现金表
有人可以帮助我吗?
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?
推荐答案
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);
}
}
这篇关于将数据集中的数据填充到VB.net 2010中的DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!