473,779 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 OleDbDataAdapat er 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.EventArg s e

OleDbDataAdapte r dataAdapter = new OleDbDataAdapte r()
DataSet dataSet = new DataSet()

//Here is the OleDbCommand object that has already been initalized with appropriate OleDbConnection objec
this.selectCust omersCmd.Comman dText = "Select * From Customers"

dataAdapter.Sel ectCommand = this.selectCust omersCmd
dataAdapter.Fil l(dataSet, "Customers" )

//Show DataTable on DataGrid objec
this.dataGridOb ject.DataSource = dataSet.Tables["Customers"].DefaultView
}
Nov 16 '05 #1
3 2483
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*******@disc ussions.microso ft.com> wrote in message
news:E3******** *************** ***********@mic rosoft.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 OleDbDataAdapat er 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.EventArg s e)
{
OleDbDataAdapte r dataAdapter = new OleDbDataAdapte r();
DataSet dataSet = new DataSet();

//Here is the OleDbCommand object that has already been initalized with appropriate OleDbConnection object this.selectCust omersCmd.Comman dText = "Select * From Customers";

dataAdapter.Sel ectCommand = this.selectCust omersCmd;
dataAdapter.Fil l(dataSet, "Customers" );

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

Nov 16 '05 #2
I get about 15 rows, it's a small test application...a nd 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.Ta bles["Customers"].Rows

MessageBox.Show (row["CustomerNa me"].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.DataBi nd(); 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*******@disc ussions.microso ft.com> wrote in message
news:11******** *************** ***********@mic rosoft.com...
I get about 15 rows, it's a small test application...a nd 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.Ta bles["Customers"].Rows)
{
MessageBox.Show (row["CustomerNa me"].ToString());
}

Nov 16 '05 #4

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

Similar topics

3
2230
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 he row.delete() in my Delete_Row sub is correct because when deleting a record from the dbase, it doesnot get deleted from the actual database, even tho on the datagrid it does show that the record is deleted: '''''''''''''
1
350
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. The goal is to initially have the footer display below the Submit Button. Once data has been filled in, a DataGrid will display data based on the criteria. The drop downs work, the DataGrid displays data correctly. The problem is that when I...
3
339
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 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,...
3
4237
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 datatable feeding the datagrid control. Both are of the DateTime Type. How do I get the time field to display only the Time, and not the date, which is apparently the default.
6
1747
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 DNS error. I developed this "simple" page but so far it is not simple! argh! <%@ Page Language="VB" Debug="true" Explicit="true" %> <%@ import Namespace="System.Data" %>
3
1561
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 it, in either design or codebehind. Thanks David
4
1517
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 VB.NET) that handles the SortCommand event of the data grid. I've included the declaration of the Sub below. EnableViewState is set to false; we reload the DataSource each time the page posts. Would anyone know why this DataGrid doesn't sort? ...
11
2499
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 to the DataTable. The code for this is lengthy and the grid is obviously not editable. I've read it's possible to connect my collection directly, and have it be editable, too. Can anyone point me to a resource that can walk me through this? ...
4
1462
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 table in the client app, I display the row contents in Textboxes. I want to display the corresponding detail data for each row in a datagrid. My question is if I can pull the master and detail data and populate the corresponding tables in the...
2
1689
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 header. After the search button gets clicked, the dataset data should filled in the datagrid. Thank you
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.