473,769 Members | 2,120 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 2481
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
1560
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
1513
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
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
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
10208
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
9857
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7404
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
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
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

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.