Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 18th, 2007, 03:48 PM
Registered User
Join Date: Feb 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL query in vb.net 2005


I am trying to load the details of shops on the form in the labels from my database. These details are first loaded into the listbox using a SQL query.

After the details are loaded onto the listbox I then want to show the details of the item that is selected from the listbox.

The problem I am facing is that it doesnt shows the details of the item selected from the listbox it just dispalys the details of the first item stored in the database.

The code i m using is as follows.

 Public Const strConnection As String = _
"Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=../project.mdb;Persist Security Info=False"

Private Sub lstShops_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstShops.SelectedIndexChanged

Dim intRow As Integer
intRow = lstShops.SelectedIndex

Dim objConnection As New System.Data.OleDb.OleDbConnection(strConnection)

Dim strSQL As String = "SELECT * FROM tblShop"

Dim objDataAdapter As New OleDb.OleDbDataAdapter(strSQL, strConnection)

Dim objDataSet As New DataSet
Dim objTable As New DataTable


objDataAdapter.Fill(objDataSet, "AllShop")

objTable = objDataSet.Tables("AllShop")



lblStoreName.Text = objTable.Rows(intRow).Item("ShopName")
txtStoreDes.Text = objTable.Rows(intRow).Item("ShopDescription")
lblOpen.Text = objTable.Rows(intRow).Item("ShopOpenTime")
lblClose.Text = objTable.Rows(intRow).Item("ShopCloseTime")
lblLocation.Text = objTable.Rows(intRow).Item("Location")
End Sub

Can someone plz help me with my SQL query?


Reply With Quote
  #2 (permalink)  
Old February 18th, 2007, 03:54 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons

Change your SQL query to something like

SELECT * from tblShop where item = '" & lstShops.SelectedItem.Text &"'"

that should return you the correct row.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET

Reply With Quote
  #3 (permalink)  
Old February 24th, 2007, 09:23 AM
Registered User
Join Date: Feb 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks dparsons

You really gave me an idea but the correct SQl statement is without dot text.

SELECT * from tblShop where item = '" & lstShops.SelectedItem &"'"


Reply With Quote
  #4 (permalink)  
Old May 2nd, 2007, 11:13 PM
Authorized User
Join Date: Dec 2006
Location: , , .
Posts: 70
Thanks: 0
Thanked 1 Time in 1 Post

Thanks for the help.
I've been throwing an exception and couldn't figure out what was 'wrong' with the SQL statement I was sending.
This topic gave me the answer.


Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
reg conn to sql server 2005 from vb.net 2005.. veda SQL Server 2005 2 July 1st, 2008 12:16 AM
VB 2005 Parameter Query mrmarkt Visual Basic 2005 Basics 0 November 25th, 2007 11:31 AM
sql query in vb.net 2005 PankajGarg10 General .NET 2 May 3rd, 2007 06:23 AM
how to pass sql query to crystal through vb.net dranjithreddy Crystal Reports 0 June 7th, 2005 05:15 AM
How can I pass sql query through vb.net to crystal sachinbashetti Crystal Reports 0 May 14th, 2005 01:47 AM

All times are GMT -4. The time now is 04:02 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.