1

I have 2 dataGridViews on a form, and when I run the app, nothing shows up. I believe that adding the dataGridView information in the code, like below, I don't need to add the database using Visual Studio's "Server Explorer". That would be redundant and/or change the fill outcome of the dataGridView, right? Am I missing something in my code??

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"];
    }
  }
}

1 Answer 1

2

Try passing the connection into the data adapter...

OleDbCommand slctOrders = new OleDbCommand("SELECT * FROM script_Orders ORDER BY script", vcon);

I'm not sure if that is all you are missing (you might also need to open the connection, vcon.Open()), but there has to be some some link between the connection object and the adapters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.