我在一个表单上有 2 个 dataGridView,当我运行应用程序时,什么也没有显示。我相信在代码中添加dataGridView信息,如下所示,我不需要使用Visual Studio的“服务器资源管理器”添加数据库。那将是多余的和/或更改 dataGridView 的填充结果,对吗?我的代码中是否缺少某些内容?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
OleDbDataAdapter daOrders = new OleDbDataAdapter();
OleDbDataAdapter daReceived = new OleDbDataAdapter();
OleDbConnection vcon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=C:\Query Form\Database.accdb");
OleDbCommand slctOrders = new OleDbCommand("SELECT * FROM script_Orders ORDER BY script");
daOrders.SelectCommand = slctOrders;
daOrders.Fill(ds, "tblOrders");
OleDbCommand slctReceived = new OleDbCommand("SELECT * FROM script_Received");
daOrders.SelectCommand = slctReceived;
daOrders.Fill(ds, "tblReceived");
dgOrders.DataSource = ds.Tables ["tblOrders"];
dgReceived.DataSource = ds.Tables ["tblReceived"];
}
}
}