473,320 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Can't Display Data in DataGrid

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
}
Nov 16 '05 #1
3 2455
Ed_P:

How many rows do you have? I'm guessing you aren't getting any back hence
it's not showing.
"Ed_P." <an*******@discussions.microsoft.com> wrote in message
news:E3**********************************@microsof t.com...
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;
}

Nov 16 '05 #2
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())
}
Nov 16 '05 #3
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." <an*******@discussions.microsoft.com> wrote in message
news:11**********************************@microsof t.com...
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());
}

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
1
by: Randy | last post by:
Can footers be forced to the bottom of an .ASPX page either using #include or User Controls? I got a page that starts out displaying 3 drop down lists, one text box, 5 labels and 1 Submit Button. ...
3
by: Ed_P. | last post by:
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...
3
by: Andrew S. Giles | last post by:
Hello, I am importing a flat text file, and putting it into a datagrid for display on a form. Currently the users have their dates and times seperated. I have two fields, therefore in the...
6
by: Teep | last post by:
Below is my code for dropdownlist that is populated from a SQL table. After a selection from the ddl, a datagrid is suppose to come up pertaining to the information selected, but I keep getting a...
3
by: david | last post by:
Since there are too many data fields (clolumns) to display, it is better for me to rotate the datagrid by 90 degrees (ie, the columns become rows in web display). Anyone here can tell me how to do...
4
by: Joe | last post by:
Hello, I have a datagrid in an nested html table (one table inside of another table) and have set the allowsSorting property to true. I've created in the code-behind a method (Sub - I'm using...
11
by: Michael Kellogg | last post by:
I have a collection of custom objects that I am displaying in a Windows Forms Datagrid. To display it, I take the collection and build a DataTable object on the fly, then set the grid's DataSource...
4
by: Rich | last post by:
Hello, I have a master and detail table in sql server. Say the master has 10 rows and detail has 45 rows. I fill 2 tables in my dataset in the client app. When I iterate through the master...
2
by: arunkumaryespee | last post by:
Hii i have a problem in display a empty datagrid with header during page_load(). actually i use the datagrid for searching purpose. During the page load i want to display an empty grid with...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.