Can't Display Data in DataGrid

G

Guest

Hello

I have a Windows Form that I am trying to use to display data in a DataGrid object from an Access Database. I have created an OleDbCommand Object (with the appropriate Connection string) to Select the appropriate data. I then use a OleDbDataAdapater to Fill a DataSet object. My problem is that I can't seem to show the results of the query on my datagrid object. Here is Code

private void btnSearch_Click(object sender, System.EventArgs e

OleDbDataAdapter dataAdapter = new OleDbDataAdapter()
DataSet dataSet = new DataSet()

//Here is the OleDbCommand object that has already been initalized with appropriate OleDbConnection objec
this.selectCustomersCmd.CommandText = "Select * From Customers"

dataAdapter.SelectCommand = this.selectCustomersCmd
dataAdapter.Fill(dataSet, "Customers")

//Show DataTable on DataGrid objec
this.dataGridObject.DataSource = dataSet.Tables["Customers"].DefaultView
}
 
W

William Ryan eMVP

Ed_P:

How many rows do you have? I'm guessing you aren't getting any back hence
it's not showing.
Ed_P. said:
Hello,

I have a Windows Form that I am trying to use to display data in a
DataGrid object from an Access Database. I have created an OleDbCommand
Object (with the appropriate Connection string) to Select the appropriate
data. I then use a OleDbDataAdapater to Fill a DataSet object. My problem
is that I can't seem to show the results of the query on my datagrid object.
Here is Code:
private void btnSearch_Click(object sender, System.EventArgs e)
{
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
DataSet dataSet = new DataSet();

//Here is the OleDbCommand object that has already been initalized with
appropriate OleDbConnection object
this.selectCustomersCmd.CommandText = "Select * From Customers";

dataAdapter.SelectCommand = this.selectCustomersCmd;
dataAdapter.Fill(dataSet, "Customers");

//Show DataTable on DataGrid object
this.dataGridObject.DataSource = dataSet.Tables["Customers"].DefaultView;
}
 
G

Guest

I get about 15 rows, it's a small test application...and I do get rows back...I have used a foreach loop to go thru the datatable and I do get the data, I have included the code for the foreach look below for your reference...I don't seem to know where to go with this so any info you can provide will be greatly appreicated

foreach(DataRow row in this.dataSet.Tables["Customers"].Rows

MessageBox.Show(row["CustomerName"].ToString())
}
 
W

William Ryan eMVP

Ed_P:

Is this a web or winforms app? if it's ASP.NET hen you need to call
DataGrid.DataBind(); after you set the datasource, if it's winforms, then
that's surprising problem indeed. If it is, let me know and I'll see what I
can come up with.

Cheers,

Bill
Ed_P. said:
I get about 15 rows, it's a small test application...and I do get rows
back...I have used a foreach loop to go thru the datatable and I do get the
data, I have included the code for the foreach look below for your
reference...I don't seem to know where to go with this so any info you can
provide will be greatly appreicated!
foreach(DataRow row in this.dataSet.Tables["Customers"].Rows)
{
MessageBox.Show(row["CustomerName"].ToString());
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top