473,701 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Display SQL results in DataGrid

Hi guys

What I'm trying to do today is display the results from
an SQL query on one table in a Datagrid I'm using the
following code to query the table.

\\\
Try

If txtCustomersIDO rders.Text <> "" Then
DataSetCustomer sOrders.Clear()

OleDbDataAdapte rCustomersOrder s.SelectCommand .CommandText
= "SELECT * FROM Orders WHERE " & "[Customer ID] = '" &
txtCustomersIDO rders.Text & "' "

OleDbDataAdapte rCustomersOrder s.Fill
(DataSetCustome rsOrders)

Else
txtCustomersIDO rders.Text = "Enter users ID here"
End If

Catch oledbExceptionp arameter As
System.Data.Ole Db.OleDbExcepti on
Catch invalidoperatio nexceptionparam eter As
InvalidOperatio nException

End Try
///

The datagrid is bound to the 'DataSetCustome rsOrders'
DataSet and a TextBox is being used to feed the WHERE
clause in the SQL statement I also know for sure that
records meeting the criteria exist but no results are
being displayed in the grid when I hit my command button
to trigger the event.

I know I could do this easily using a DataView / Filter
but I would really like to get it working through SQL for
my own benefit

Thanks in advance

Regards Steve
Nov 20 '05 #1
2 2329
Cor
Hi Steven,

I mis the connection in your text.
If you already have done a query in some statements before, it maybe will
work

But because the way you do that catch of the exceptions I think it does
nothing.

Doing in that way the catch is absolute something you never should do.

In that way you program run but does nothing or maybe even dangerous
operations.

After every catch has to be an action, the minimum is
messagebox.show (exception.tost ring)

I dont do the filling of a dataset it the way you do, I do it mostly like
this
\\\
Dim Conn As New OleDbConnection (connectionstri ng)
Try
Dim cmd As New OleDbCommand(sq lStr, Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapte r(cmd)
da.Fill(ds, "table")
etc
//

But you can try the way you did, I did not see it complete in the
documentation, but you can try by adding what I wrote between the rows,
because when the dataadaper command knows the connection, it is not
impossible that it works. (If a dataconnection is not open the datadapter
does it himself)

If you do it that way, tell me if it did work will you?

Cor
OleDbDataAdapte rCustomersOrder s.SelectCommand .CommandText
= "SELECT * FROM Orders WHERE " & "[Customer ID] = '" &
txtCustomersIDO rders.Text & "' "
OleDbDataAdapte rCustomersOrder s.SelectCommand .Connection =
(Your OleDbConnection )
OleDbDataAdapte rCustomersOrder s.Fill
(DataSetCustome rsOrders)

Else
txtCustomersIDO rders.Text = "Enter users ID here"
End If

Catch oledbExceptionp arameter As
System.Data.Ole Db.OleDbExcepti on
Catch invalidoperatio nexceptionparam eter As
InvalidOperatio nException

End Try
///

Nov 20 '05 #2
Cor
Hi Steven,

It would be a hell of a job to find the name of that already opened
connection.

But as far as I know you can use more connections in one program.

You need a connection string.
You find it in that initialize part, but you can also look here

http://www.connectionstrings.com/

And then that code in the end yes and all comments I placed between.

I should then not know why it would not work

But if not message, but your problem is simple for me, maybe I made a typeo
somewhere.

Cor
The connection is opened here and is used for other
INSERT, UPDATE & DELETE commands elsewhere in the
application so it must remain live

\\\
Public Sub New()
MyBase.New()

'This call is required by the Windows Form
Designer.
InitializeCompo nent()

'Add any initialization after the
InitializeCompo nent() call
OleDbConnection 1.Open()
End Sub
///

I added messages to the catch statements and this one is
always thrown:
Because there is no connection yes.

\\\
Catch oledbExceptionp arameter As
System.Data.Ole Db.OleDbExcepti on
MessageBox.Show
("System.Data.O leDb.OleDbExcep tion")
///

But my grid still does not show any results
To use your method I should replace:

\\\
OleDbDataAdapte rCustomersOrder s.Fill
(DataSetCustome rsOrders)
///

with

\\\
dim connectionstrin g as string = "the founded connectionstrin g"
dim sqlStr = "that created sql string of you"
Dim Conn As New OleDbConnection (connectionstri ng)
Try
Dim cmd As New OleDbCommand(sq lStr, Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapte r(cmd)
da.Fill(ds, "table")
here the right datasetname and table name (the table name is not really
necassery)
///

Cor
Nov 20 '05 #3

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

Similar topics

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,...
1
2406
by: kll | last post by:
I have been on newsgroup for week. I have seen anything that will help me. Basically, I have a form with a datagrid that can be sorted or unsorted (it is up to the user). Then, I display the data of the selected row in textboxes on dialog that execute by the user press a button. The following code works if I do not sort the datagrid before I press the button to bring up the dialog. It is when I sort it the datagrid I have the issue ...
3
4234
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.
4
2202
by: Tim T | last post by:
Hi, I have a stored procedure executing a search and an asp.net page displaying the results in a datagrid. The datagrid has paging on it, I am using Visual Studio.NET and can't see any option to show the number of results found. Is there an easy way to add this to the top of the datagrid, along with the total number of pages ie: 67 resuts found page 1 of 7 (where the numbers in are hyperlinks to that
1
1003
by: Kenneth Keeley | last post by:
Hi, Can I configure what a datagrid will look like if no results are found for it to bind to. I would like it to say something like "No Results Found please try again." All I get at the moment is a blank datagrid with the heads all showing and no results. Thanks Kenneth
2
1460
by: csgraham74 | last post by:
Hi guys, just wondering if someone could help me a little. i have a piece of xml being returned to my page. This xml can vary depending on criteria that i select and submit. my issue is that when the data is returned i wish to display the result in a table. Im not sure what the best way is to do this. should this be done in a datagrid that i create dynamically or can i draw an html
3
4419
by: Jimmy | last post by:
Hi I want to display an empty datagrid if my datasource has zero results. How to do this? thanks J.
4
6929
by: neena | last post by:
how to display values from database tables without using datagrid control in C# .net.I want to search the values from database & the search results to be shown as rows in the web form,without the use of datagrid.So any one plz help me.
5
2451
by: nirmala26 | last post by:
I have a webpage that displays the results of a search query on a Datagrid. The datagrid is shown completely fine on IE 6.0 but when i access the webpage from IE 7.0, the datagrid is shown only partially. Also in some pages, the buttons overlap when it comes to IE 7.0 Can anyone please help with what I need to check to get this resolved ? Thanks.
0
8738
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
9085
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...
0
8936
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
6575
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
5905
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
4411
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
4665
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3104
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
2036
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.