473,474 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Create 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 txtCustomersIDOrders.Text <> "" Then
DataSetCustomersOrders.Clear()

OleDbDataAdapterCustomersOrders.SelectCommand.Comm andText
= "SELECT * FROM Orders WHERE " & "[Customer ID] = '" &
txtCustomersIDOrders.Text & "' "

OleDbDataAdapterCustomersOrders.Fill
(DataSetCustomersOrders)

Else
txtCustomersIDOrders.Text = "Enter users ID here"
End If

Catch oledbExceptionparameter As
System.Data.OleDb.OleDbException
Catch invalidoperationexceptionparameter As
InvalidOperationException

End Try
///

The datagrid is bound to the 'DataSetCustomersOrders'
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 2321
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.tostring)

I dont do the filling of a dataset it the way you do, I do it mostly like
this
\\\
Dim Conn As New OleDbConnection(connectionstring)
Try
Dim cmd As New OleDbCommand(sqlStr, Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(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
OleDbDataAdapterCustomersOrders.SelectCommand.Comm andText
= "SELECT * FROM Orders WHERE " & "[Customer ID] = '" &
txtCustomersIDOrders.Text & "' "
OleDbDataAdapterCustomersOrders.SelectCommand.Conn ection =
(Your OleDbConnection)
OleDbDataAdapterCustomersOrders.Fill
(DataSetCustomersOrders)

Else
txtCustomersIDOrders.Text = "Enter users ID here"
End If

Catch oledbExceptionparameter As
System.Data.OleDb.OleDbException
Catch invalidoperationexceptionparameter As
InvalidOperationException

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.
InitializeComponent()

'Add any initialization after the
InitializeComponent() call
OleDbConnection1.Open()
End Sub
///

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

\\\
Catch oledbExceptionparameter As
System.Data.OleDb.OleDbException
MessageBox.Show
("System.Data.OleDb.OleDbException")
///

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

\\\
OleDbDataAdapterCustomersOrders.Fill
(DataSetCustomersOrders)
///

with

\\\
dim connectionstring as string = "the founded connectionstring"
dim sqlStr = "that created sql string of you"
Dim Conn As New OleDbConnection(connectionstring)
Try
Dim cmd As New OleDbCommand(sqlStr, Conn)
Dim ds As New DataSet
Dim da As New OleDbDataAdapter(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
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...
1
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...
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...
4
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...
1
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...
2
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...
3
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
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...
5
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...
0
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,...
0
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,...
1
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...
0
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...
0
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,...
1
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...
0
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...
0
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.