以下是在数据网格视图中显示数据库表记录的代码
try
{
Query = "Select Code,Description,Rate,Bottles from Items ";
dba = new SQLiteDataAdapter(Query, GlobalVars.conn);
testDs = new DataSet();
dba.Fill(testDs, "Items");
dtgitems.DataSource = testDs.Tables[0];
dtgitems.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
最初的表格是什么?加载数据网格视图shouold显示空行以插入新记录。我怎么能做到这一点?谢谢
答案 0 :(得分:0)
dba.Fill(testDs, "Items");
dtgitems.AllowUserToAddRows = true;
dtgitems.EditMode = DataGridViewEditMode.EditOnKeystroke;
dtgitems.DataSource = testDs.Tables[0];
答案 1 :(得分:0)
当我希望我的gridview变空时,我使用此代码希望它有所帮助
DataTable dtable = new DataTable();
BindingSource bsource = new BindingSource();
DataSet dset = new DataSet();
dtable.Columns.Add("Delete");
dtable.Columns.Add("FileName");
dtable.Columns.Add("FileVersion");
dtable.Columns.Add("FileSize");
dtable.Columns.Add("InstallFolder");
dtable.Columns.Add("fnameorig");
dset.Tables.Add(dtable);
bsource.DataSource = dset.Tables[0].DefaultView;
Gridview1.DataSource = bsource;