Wrox Programmer Forums
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 18th, 2007, 03:48 PM
Registered User
Join Date: Feb 2007
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?


Old February 18th, 2007, 03:54 PM
Wrox Author
Join Date: Oct 2005
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

Old February 24th, 2007, 09:23 AM
Registered User
Join Date: Feb 2007
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 &"'"


Old May 2nd, 2007, 11:13 PM
Authorized User
Join Date: Dec 2006
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.


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

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