473,626 Members | 3,467 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to display text files from a database

15 New Member
Hi, please help I've been wrestling with this for a very long time and its not working. I'm trying to display text files from a database when someone selects one or more list items of my listbox. The list box contains names of various professions. The database I'm accessing contains Resumes field, Professions field, and ResumesID field. When a user selects one or more list items, the profession in the Professions field that match the text of the selected listitem, will be selected. The resumes corresponding to the profession is also selected and retrieved for displaying. Please help me display the resumes in a label or text area. The following is my code, thank you in advance for your help.


Private Sub ListBox2_Select edIndexChanged( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ListBox2.Select edIndexChanged

Dim myCon As OdbcConnection
Dim i As Integer
Dim cmd As OdbcCommand
For i = 0 To ListBox2.Items. Count - 1
If ListBox2.Items( i).Selected Then

myCon = New OdbcConnection( "Driver={My SQL ODBC 3.51 Driver};Server= myServer;Databa se=myDatabase;U ser=myUserasswo rd=myPass;Optio n=3;")
cmd = New OdbcCommand("SE LECT * FROM myTable where Professions = '" & ListBox2.Items( i).Text & "'")

End If
Next
If Not IsNothing(myCon ) Then
myCon.Open()

cmd.Connection = myCon

Dim ds As New DataSet

Dim ad As New OdbcDataAdapter (cmd)

ad.Fill(ds)

Me.ListBox2.Dat aSource = ds

Me.ListBox2.Dat aTextField = "ResumesID"
Me.ListBox2.Dat aTextField = "Resumes"
Me.ListBox2.Dat aBind()

End If
End Sub
Jul 24 '07 #1
3 1689
RoninZA
78 New Member
So where is the problem, how is your code not working?

I see you are setting the DataTextField property for ListBox2 twice, that not maybe the problem?
Jul 24 '07 #2
WebNewbie
15 New Member
Hi, thanks for responding, that was an error I have fixed already and that line is now
Me.ListBox2.Dat aValueField = "Resumes"

Also the select statement has been changed to

("SELECT ResumesID,Resum es FROM contenttbl where Professions = '" & ListBox2.Items( i).Text & "'")

Unfortunately the changes didn't help.Can you tell me how to edit my post,? I'm new here and I can't seem to find the Edit option.
Jul 24 '07 #3
RoninZA
78 New Member
OK, sorry, I must've still been asleep when I read your first post...

The problem is that you're filling your dataset outside the FOR loop...

What I would suggest you do is to change your code to create the connection outside the FOR loop, and use the FOR loop to generate a SQL statement with a 'IN' where clause, and then filling your dataset AFTER the loop, ie something like this:
Expand|Select|Wrap|Line Numbers
  1. Dim myCon As OdbcConnection
  2. Dim i As Integer
  3. Dim cmd As OdbcCommand
  4. Dim sqlCommand As String
  5.  
  6. sqlCommand = "SELECT * FROM myTable where Professions IN ("
  7.  
  8. For i = 0 To ListBox2.Items.Count - 1
  9.     If ListBox2.Items(i).Selected Then
  10.          sqlCommand = sqlCommand + "'" & ListBox2.Items(i).Text & "',"
  11.     End If
  12. Next
  13.  
  14. 'Trim out the last comma, replacing it with a ) to complete the SQL statement
  15. sqlCommand = sqlCommand.SubString(1, sqlCommand.Length - 1) + ")"
  16.  
  17. myCon = New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=myServer;Database=myDatabase;User=myUser;Password=myPass;Option=3;")
  18. myCon.Open()
  19. cmd = New OdbcCommand(sqlCommand, myCon)
  20.  
  21. Dim ds As New DataSet
  22. Dim ad As New OdbcDataAdapter(cmd)
  23.  
  24. ad.Fill(ds)
  25.  
  26. Me.ListBox2.DataSource = ds
  27. Me.ListBox2.ValueMember = "ResumesID"
  28. Me.ListBox2.DisplayMember = "Resumes"
  29.  
I haven't really tested this code, and my VB is a little rusty, but this should point you more or less in the right direction.

Good luck.
Jul 24 '07 #4

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

Similar topics

4
4122
by: hoke | last post by:
I want to display plain text files in the browser. The files contain html and javascript and have a .txt extension. This works fine with files with just html. Unfortunately when showing files with javascript, I get an "error on page" warning and the page is not displayed. I suppose that when Internet Explorer discovers a <script> tag he starts to interpret it. This is not what I want. After all Internet Explorer is a browser and not an...
19
6871
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the JavaScript in this code from a couple different sites but I'm not 100% sure what each line is doing...This is the ASP code that I'm using for the page....Take a look at the JavaScript code and please let me know what each line is doing....I have been...
3
5908
by: Ken | last post by:
I have a database called autographs.mdb that is in the "XYZ" folder in the "database" folder. I have a form in the database that I want to display a photo of the celeb on. The photos are in a "graphics" folder that is on the same level as the "xyz" folder. The only way I can seem to make it work is to put the entire path including hard drive in the table (c:\database\graphics\photo.jpg). But I also want to upload the database to the web...
0
5807
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database which indexes computer magazine articles for personal reference. I am developing a Visual Basic.NET program whose sole purpose is to enter new records into the database. No updates to existing entries, no deletions, and no display
5
5027
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page that calls the web service to render a vertical strip of images. After doing some research I am unable to find some vb.net code that can assist in what I want to achieve. The closest thing I found was
3
3887
by: jiayanxiang | last post by:
Is there any sample code to use Javascript to load and display a text file? It will be best if the user can select files using some kind of explorer. If that's complex, a text box to specify the file name will be fine as well. Once a text file is selected, I just need to display it in a text box. Thanks for the help.
3
5232
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from database and display it in a Image web control dynamically(at runtime). The process after being displayed in the web control, user click insert/add button, it converts the image(jpeg) file to bytes and store it the database with Image or VarBinary...
9
8839
by: Suman | last post by:
Happy Friday everyone!!! I am working on a windows service and a C# application and needed some help with certain functionality. Please read through my issue below. Thanks! I have a windows service which writes into a log file periodically (text file). I want to create a windows form application, which, upon invocation should continuously display the contents of the log file. Even the newly made entries into the log file while the...
1
3693
by: sunnyluthra1 | last post by:
Hi Everyone, I am working on a piece of code, that displays the properties(Name, Datatype, size & Description) of the table in the database. Now I want to further Enhance the code. I Have created a form in MS Access, on that form, I have 2 buttons & a text box. One button is to select a mdb file, whom properties i want to display. Second button then stores that properties in a Excel file. when I open the file using first button, the path of...
0
8268
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8202
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7199
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4093
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1812
muto222
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.