473,473 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Select Statement

Hi
I need to use a listbox to display authors from the authors table in the
standard BIBLIO.MDB. I haven't even got to this point yet and the code
below is bombing out on the line 'dataAdapter.Fill(dt)'.
If I only run 'Select * from Titles' then it works fine. Even if I try
'Select Titles.title from .....' it bombs.
Please help
Thanks
Carlo

Dim title, publisher As String
title = txtTitle.Text
Dim dt As New DataTable()
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source = BIBLIO.MDB"
Dim sqlstr As String = "Select * from Titles inner join 'Title
Author' on Titles.ISBN = 'Title Author'.ISBN inner join Authors on Title
Author.Au_ID = Authors.Au_ID where isbn = '0-0038326-7-8'"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlstr, connstr)
dataAdapter.Fill(dt)
dataAdapter.Dispose()
lstDisplay.DataSource = dt
lstDisplay.DisplayMember = "Title"
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
6 1406
Carlo:

I'd highly recommend against using joins like this. Assuming that syntax is
correct, you are still begging for trouble. You have a field with spaces in
it and you'll need to use [FirstPart SecondPart] instead of single quotes.
The reasons for both have been belabored in the various ngs, but in sum,
using joins like this is very inefficient, makes dataadapter updates
nightmarish at best and makes is very costly. Having field names like that
invites disaster. At some point in the future, either you or some other
/new developer will forget to use the [] and teh query will bomb. time will
be spent tracking it down, time will be spent fixing it and time will be
spent distributing it. No matter how careful you are, the odds are against
you and it will probably cause at least one problem. Depending no the
circumstances, the client might not care, or they might decide it's the
straw that breaks the camels back. Either way it's a lot of risk just to
keep a bad habit.

Here's a discussion of using the datarelation instead of using Joins.
http://www.knowdotnet.com/articles/datarelation.html
Finally, do yourself one other favor and get rid of the concatenated dynamic
sql. This has also been beat into the ground over and over but in short,
it's very error prone, inefficient, a huge security risk and no matter how
careful you are, you'll get a last name like O'Brien or some other thing
with a ' in it and you'll have to find it, fix it, redistribute the fix, all
the while causing the customer unnecessary inconvenience. Another thing
that has a lot of downside just to keep a bad habit in place.

Don't mean to lecture, but these things are 'bad' precisely b/c they cause
problems like the one you are experiencing. You may be experiencing
something else too, but the space issue is almost surely one of the problem.

If you have any questions, let me know.

Cheers,

Bill
"Carlo B" <ca****@global.co.za> wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...
Hi
I need to use a listbox to display authors from the authors table in the
standard BIBLIO.MDB. I haven't even got to this point yet and the code
below is bombing out on the line 'dataAdapter.Fill(dt)'.
If I only run 'Select * from Titles' then it works fine. Even if I try
'Select Titles.title from .....' it bombs.
Please help
Thanks
Carlo

Dim title, publisher As String
title = txtTitle.Text
Dim dt As New DataTable()
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source = BIBLIO.MDB"
Dim sqlstr As String = "Select * from Titles inner join 'Title
Author' on Titles.ISBN = 'Title Author'.ISBN inner join Authors on Title
Author.Au_ID = Authors.Au_ID where isbn = '0-0038326-7-8'"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlstr, connstr)
dataAdapter.Fill(dt)
dataAdapter.Dispose()
lstDisplay.DataSource = dt
lstDisplay.DisplayMember = "Title"
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #2
Hi Carlo,

I like your approach, in this way you get a fine nice dataset.

However I am not a SQL man. So I am not sure if it is because you are using
a datatable instead of a dataset or in the select. Probably your error is in
the select, you can see that better when you build a try and catch block
around your fill. (I have changed the code beneat for it and maybe because
you are using a dataset with that code you will not get an error at all)

Dim title, publisher As String
title = txtTitle.Text
Dim ds As New DataSet()
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source = BIBLIO.MDB"
Dim sqlstr As String = "Select * from Titles inner join 'Title
Author' on Titles.ISBN = 'Title Author'.ISBN inner join Authors on Title
Author.Au_ID = Authors.Au_ID where isbn = '0-0038326-7-8'"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlstr, connstr)
Try
dataAdapter.Fill(ds)
Catch sqlExc As SqlException
MessageBox.Show(sqlExc.ToString)
Catch exc As Exception
MessageBox.Show(exc.Message)
End Try

' dataAdapter.Dispose()

What is the deeper reason of that dispose? As far as I can see see you have
created the adapter global, so now you can use it only time, while there
will be no harm at all as far as I know by not disposing it.
lstDisplay.DataSource = ds.tables(0)
lstDisplay.DisplayMember = "Title"

I hope this will help?

Cor
Nov 20 '05 #3
Hi Cor:

I was just wondering what your experience has been with the join? I've
found it very problematic b/c update logic is next to impossible (I may just
not know how to do it) and you end up pulling over redundant data which is a
performance hindrance. Using a datarelation instead has always worked for
me b/c I can pull over less overall data, update logic is simple and I can
still take advantage of my constraints.

Have you been able to get around this? Particularly, what does update logic
look like? If this is doable I'd definitely like to know how.

Thanks again,

Bill
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Os*************@TK2MSFTNGP11.phx.gbl...
Hi Carlo,

I like your approach, in this way you get a fine nice dataset.

However I am not a SQL man. So I am not sure if it is because you are using a datatable instead of a dataset or in the select. Probably your error is in the select, you can see that better when you build a try and catch block
around your fill. (I have changed the code beneat for it and maybe because
you are using a dataset with that code you will not get an error at all)

Dim title, publisher As String
title = txtTitle.Text
Dim ds As New DataSet()
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source = BIBLIO.MDB"
Dim sqlstr As String = "Select * from Titles inner join 'Title
Author' on Titles.ISBN = 'Title Author'.ISBN inner join Authors on Title
Author.Au_ID = Authors.Au_ID where isbn = '0-0038326-7-8'"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlstr, connstr)
Try
dataAdapter.Fill(ds)
Catch sqlExc As SqlException
MessageBox.Show(sqlExc.ToString)
Catch exc As Exception
MessageBox.Show(exc.Message)
End Try

' dataAdapter.Dispose()

What is the deeper reason of that dispose? As far as I can see see you have created the adapter global, so now you can use it only time, while there
will be no harm at all as far as I know by not disposing it.
lstDisplay.DataSource = ds.tables(0)
lstDisplay.DisplayMember = "Title"

I hope this will help?

Cor

Nov 20 '05 #4
TO me it looks like the error is here

Dim sqlstr As String = "Select * from Titles inner join 'Title Author' ...
Single quotes are used in SQL to offset a string, so the SQL is thinking you
have a string literal here instead of a table name. try replacing with []
instead. I may be off track, but thats my giut instict. Also, the select *
will return all data from all joined tables. if you only want from title,
should make it Titles.*

Dim sqlstr As String = "Select Titles.* from Titles inner join [Title
Author] ...
"Carlo B" <ca****@global.co.za> wrote in message
news:u7**************@TK2MSFTNGP10.phx.gbl...
Hi
I need to use a listbox to display authors from the authors table in the
standard BIBLIO.MDB. I haven't even got to this point yet and the code
below is bombing out on the line 'dataAdapter.Fill(dt)'.
If I only run 'Select * from Titles' then it works fine. Even if I try
'Select Titles.title from .....' it bombs.
Please help
Thanks
Carlo

Dim title, publisher As String
title = txtTitle.Text
Dim dt As New DataTable()
Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" &
"Data Source = BIBLIO.MDB"
Dim sqlstr As String = "Select * from Titles inner join 'Title
Author' on Titles.ISBN = 'Title Author'.ISBN inner join Authors on Title
Author.Au_ID = Authors.Au_ID where isbn = '0-0038326-7-8'"
Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlstr, connstr)
dataAdapter.Fill(dt)
dataAdapter.Dispose()
lstDisplay.DataSource = dt
lstDisplay.DisplayMember = "Title"
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #5


Thanks for all the tips. The more info the better!
I'm just starting out and the text book I'm using has a chapter using
'joins' etc and I'm trying to go through the questions at the end of
each chapter based on the chapter.
Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #6
Hi Bill and Carlo

I started to tell that I do not like SQL so I have already long time the
same approach as you show.
However I do not like it, there is to much data in my opinion taken into the
dataset.

What I did not know whas this
http://support.microsoft.com/default...b;en-us;318646

It says: (read further after it, because I made it almost complete)
----------------------------------------------------------------------------
-------------------
If you use the Query Builder tool as part of the Data Adapter Configuration
Wizard for the OLEDBDataAdapter object, and you connect to a Microsoft
Access database with the Microsoft Jet OLEDB provider, query syntax that
involves more than one table join may be generated incorrectly. This will
result in an error that resembles the following (table and column names are
for illustration purposes only):

Syntax error (missing operator) in query expression 'Employees.EmployeeID =
Orders.EmployeeID INNER JOIN [Order Details] ON Orders.OrderID = [Order
Details].OrderID INNER JOIN Customers ON Customers.CustomerID =
Orders.CustomerID
----------------------------------------------------------------------------
--------------------
I did try it because I was also curious how this could be done and than I
came in what is beneath(every try deleted). I think when Bill sees this I do
not have to tell him how to create the update etc from the tables. .

\\\
Dim Sql As String = "SELECT * from A, B Where " & _
"A.n = B.n AND A.n = 10"
Dim Conn As New OleDbConnection(connString)
Dim da As New OleDbDataAdapter(Sql, Conn)
da.Fill(ds, "A")
da.Fill(ds, "B")
Conn.Close()
'In this sample the datarelation is in my opinion not needed
'However without that A.n = 10 than it is needed
'------------------------------
Dim drlA As New DataRelation _
("AA", ds.Tables("A").Columns("A.n"), _
ds.Tables("B").Columns("B.n"))
ds.Relations.Add(drlA)
Dim dv As New DataView(ds.Tables("A"))
DataGrid1.DataSource = dv
DataGrid1.Expand(-1)
////
'Without datarelation just change dv in ds

I hope this makes things clear also for you both?

Cor
Nov 20 '05 #7

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

Similar topics

21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
0
by: Jan | last post by:
I store sql-commands in a database table. In the first step I get the sql command out of the database table with embedded sql. In the second step I try to execute the command, which i got from the...
3
by: dumbledad | last post by:
Hi All, I'm confused by how to replace a SELECT statement in a SQL statement with a specific value. The table I'm working on is a list of words (a column called "word") with an index int...
4
by: 001 | last post by:
Hello, The select statement needs only 1 second to complete the query. But the update statement spends 30 minutes. Why? SELECT STATEMENT: declare @IDate smalldatetime select @IDate=col001...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Grant McLean | last post by:
Hi First a simple question ... I have a table "access_log" that has foreign keys "app_id" and "app_user_id" that reference the "application_type" and "app_user" tables. When I insert into...
6
by: Bob Stearns | last post by:
I am getting duplicate rows back from a select distinct statement of the form: SELECT DISTINCT 'jhough', '000111', t0.bhid FROM (SELECT lots of good stuff) t0 LEFT OUTER JOIN another_table ...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
0
FishVal
by: FishVal | last post by:
Hereby I'm proposing a way of convinient work with properties containing SQL Select statements, particulary RowSource property of ComboBox and ListBox. The usual way is the following. Private...
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,...
0
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...
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.