473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VB2008/MS Access problems

Greetings,

I have a program setup for which I would like to pull specific data from an Access database I have created. I know the connection to the database is functioning as I can pull mass data to populate a list box. Where I am having trouble is this. I would like to select a name from said list box and have the database return only information based on the name selected. Once I pull this information I would like to then place each item from this data into it's relevant place on the form. I'd rather not do this using a datagrid on the form. This is what I have currently.

*Note, the names being displayed in the list box is a direct match to the primary keys of each row

Expand|Select|Wrap|Line Numbers
  1. Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
  2.         Dim selectedchar As String = characterlst.SelectedItem
  3.         Dim dt As New DataTable
  4.  
  5.         con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\Tech\My Documents\4e.mdb;"
  6.         con.Open()
  7.         sql = "SELECT * FROM details WHERE [Name]=" & selectedchar
  8.         da = New OleDb.OleDbDataAdapter(sql, con)
  9.         da.Fill(ds, "opening")
  10.         Try
  11.             Form1.Nametxt.Text = ds.Tables("opening").Rows(0).Item(0)
  12.         Catch ex As Exception
  13.             MessageBox.Show(ex.Message & " - " & ex.Source)
  14.         End Try
  15.  
  16.         con.Close()
  17.  
  18.         Me.DialogResult = System.Windows.Forms.DialogResult.OK
  19.         Me.Close()
  20.     End Sub
  21.  
When I run this code it gives me an error saying
"no value given for one or more required parameters vb access"

If I change the select statement to read

"SELECT * FROM details WHERE Primary Key =" & selectedchar
it throws me an error saying the syntax is incorrect

In both instances the error is thrown at line 8.

Any help would be much appreciated.
Sep 24 '08 #1
2 1843
debasisdas
8,127 Expert 4TB
you need to select an item from characterlst before going for the clock event of the button
Sep 25 '08 #2
Meant to update this actually. The problem was this.

I was using

characterlst.selecteditem

when I should have been using

characterlst.text

.selecteditem was returning and integer value for the list location of the selected object instead of the actual text of the selection.

combine that with the fact that for the query to function properly it needed to be done as thus

"Select * FROM details Where name=" & "'" & selectedchar & "'"

the proper/working code is as follows

Expand|Select|Wrap|Line Numbers
  1. Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
  2.         Dim selectedchar As String = characterlst.Text
  3.         con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\Tech\My Documents\4e.mdb;"
  4.         con.Open()
  5.         sql = "SELECT * FROM details WHERE name='" & selectedchar & "'"
  6.         da = New OleDb.OleDbDataAdapter(sql, con)
  7.         da.Fill(ds, "opening")
  8.         Try
  9.             Form1.Nametxt.Text = ds.Tables("opening").Rows(0).Item(0)
  10.             Form1.Racecmb.SelectedItem = ds.Tables("opening").Rows(0).Item(1)
  11.         Catch ex As Exception
  12.             MessageBox.Show(ex.Message & " - " & ex.Source)
  13.         End Try
  14.  
  15.         con.Close()
  16.         Form1.Enabled = True
  17.         Me.DialogResult = System.Windows.Forms.DialogResult.OK
  18.         Me.Close()
  19.     End Sub
  20.  
Sep 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Arthur Dent | last post by:
Does anyone know where i can find a decently thorough list of the language changes in VB2008, such as the new If() function? All i can seem to find through search engines, most of the articles...
2
by: Arthur Dent | last post by:
I am trying to make a VB2008 Express winforms project, and edit the form. However, when i try to open the form, i get this error: ..NET Framework 2.0 update not found. The win32manifest will not...
6
by: Academia | last post by:
I have a computer at home with a (slow) dialup connection and a computer at school with a fast connection. I want to go there (it is not close) and down load Vb2008 express, burn it into a CD,...
8
by: Galen Somerville | last post by:
My graphics involves a lot of line drawings in a short period of time. I have all the graphics in a separate module. I repeatedly get the pixel data from a USB device, draw the requisite traces,...
6
by: Scott Gravenhorst | last post by:
Windows XP SP3 My application is set to open a SaveFile dialog when an exit is requested. When I click the app's close button, the save dialog opens, but when I click to change the folder, the...
9
by: MichaelH | last post by:
Are there any definite advantages of VB2008 over VB2005? Thank in advance. Michael
10
by: Gilbert Tordeur | last post by:
Bonjour. N'y aurait-il pas depuis la VB8 un moyen d'assigner en une seule instruction l'ensemble des propriétés d'un objet aux propriétés de mêmes noms d'un autre objet, plutôt que d'écrire la...
2
by: John Whitworth | last post by:
Hi, I'm rewriting an old VB6 app of mine in VB2008. All has been going well with calls to winscard.dll, until I needed to send an array of bytes as part of a structure. When using a winscard...
0
by: John Dann | last post by:
Looking to migrate from VB2005 Pro to VB2008. Can anyone suggest/recommend a VB2008 book that highlights the changes from earlier versions of VB.Net (VB2003/2005) rather than describing VB2008...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...

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.