以软件【银行业会计技能训练系统】为例,如下图,如何只展示access数据库中皮肤的ID和皮肤名?
方法及代码如下:
打开数据库
OleDbConnection oledb3 = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + Application.StartupPath + @"\jineng.accdb;"); oledb3.Open();
选择条件如下
string sql3 = "select 皮肤,状态 from [skin]";
填充dataGridView
System.Data.OleDb.OleDbDataAdapter da3 = new OleDbDataAdapter(sql3, oledb3); DataTable dt3 = new DataTable(); try { da3.Fill(dt3); if (dt3.Rows.Count >= 1) { dataGridView2.DataSource = dt3; } } catch (Exception ex1) { throw new Exception(ex1.ToString()); } finally { oledb3.Close(); oledb3.Dispose(); da3.Dispose(); }