473,809 Members | 2,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with display query to a multiline textbox

6 New Member
Hi, I’m having trouble with my code and I’m starting to get lost. The Program takes the country that’s been typed in to the textbox and when the query button is clicked the program queries an access database for all records that contain the selected country. I think that part works, but I’m having trouble with the output. I want to display only certain fields of the record in a multiline text box, each matching record to a new line, like this…
Bob, UK, 99946, red
Joe, UK, 87777, Blue
Mary, UK, 48565, green

The database I name is TestDB, the table is InfoTable and the fields are Ename, Region, Enumber, Ecolour. Here’s the code…

Expand|Select|Wrap|Line Numbers
  1.  Imports System.IO
  2. Imports System.Data
  3. Imports System.Data.OleDb
  4. Public Class Test
  5.     Dim myString As String
  6.  
  7.     Private Sub Test_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8.  
  9.     End Sub
  10.  
  11.  
  12.     Private Sub butQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butQuery.Click
  13.         myString = txtRegion.Text.ToString()
  14.         Dim cs As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\VB\Test\TestDB.mdb"
  15.         Dim cn As New OleDb.OleDbConnection(cs)
  16.         Dim dt As New DataTable
  17.         Dim dSet As New DataSet
  18.         Dim sqlString As String
  19.  
  20.         sqlString = "SELECT Ename, Enumber, Ecolour FROM CMSDB WHERE Region = '" & myString & "'"
  21.         Dim cmd As New OleDb.OleDbCommand(sqlString, cn)
  22.         cmd.Parameters.Add("@myString", OleDb.OleDbType.VarChar, 30).Value = myString
  23.         Dim da As New OleDb.OleDbDataAdapter(cmd)
  24. da.Fill(dt)
  25.  
  26.     End Sub
  27.  
  28. End Class
Now thats the code and as far as I know it works ok, but when I try the code for the output to the multiline textbox it doesn’t work so good. Here’s the code… (this code goes right under the da.Fill(dt) above…

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.         For Each dRow As DataRow In dSet.Tables("myTable").Rows
  4.             For Each dCol As DataColumn In dRow
  5.                 txtQuery.Text = txtQuery.Text & " " & dCol.ToString()
  6.             Next dCol
  7.  
  8.             txtQuery.Text = txtQuery.Text & vbCrLf
  9.         Next dRow 

If anyone can help me get the code working that would be great.
I also seem to get this error “Expression is of type 'System.Data.Da taRow', which is not a collection type.” The error pops up on dRow from this line…
Expand|Select|Wrap|Line Numbers
  1.  For Each dCol As DataColumn In dRow 
Could someone help me get the output code working?
Cheers,
Jack
Mar 21 '07 #1
0 1529

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

Similar topics

7
4052
by: Joel Finkel | last post by:
Folks, I have a form that has several TextBoxes, some of which have the TextMode set to MultiLine. Each is pre-loaded with data from a database. The user is allowed to modify each entry. The problem is that only the modified data from the SingleLine TextBoxes are returned. The original data are returned for the MultiLine TextBoxes. Also, if the page is sent to the server (for validation, for instance), only the modified data for the...
0
984
by: Eric | last post by:
Visual C++ 2005 Express MVP's and experience programmer's only please!... I need to get the number of lines in a textbox so I can insert them into a listview. The text comes from my database and is unformatted. I display the text to my user in the listview. The textbox I create logically in the program, and I initialize the correct properties for a normal multiline editor.
0
4093
by: Luke Herbert | last post by:
I am very new to C# and have been trying to get to grips with it by writing a small tool to detect a USB key being inserted and then backup user specified files to the key. I have written some code and been able to construct a WMI query and can even get the output of this query to display to the console but not to a TextBox on my form. I fear it is embarassingly obvious but having looked at a whole heap of books (not read them in their...
1
1905
by: Jeff | last post by:
hey asp.net 2.0 In my website I've got a textbox with TextMode=MultiLine. The user can enter text that contain "new line"... But to displays this I'm also using a textbox with TextMode=MultiLine and ReadOnly=True. The textbox displays a ugly border arround the textbox, including scrollbars
0
2412
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event, which I am). I now want to read the text/values of those controls. I have found out that I can read the values if I wait until Page_Load, but then I have the same questions showing up again (along with the new questions) and I do not want them to....
5
1659
by: Ian Tedridge | last post by:
If I have 3 textboxes on a form plus 1 multiline textbox. How can I add the text from textbox 1 to 3 to the multiline textbox ? I can add the 3 textbox contents to one line of the multiline textbox, but need each text line to appear on seperate lines. this is driving me crazy, please help
2
3435
by: Mike | last post by:
I am trying to write a little program for my own use using VB2005 express edition. I have a list of peoples names in a file that I read into an array of strings. I am using a multiline textbox to enter new, edit existing, and view the names in the array. This all works well, but now I want to be able to select one more names from the list displayed in the multiline textbox then click a button to copy the selected names into another list so...
4
12540
by: anniebai | last post by:
Please help me with writing a RowUpdating function in C#, I don't know how to grab the current field's value and also get the old value for one of keys (which is ProjectName for editing) of the selected row. I've tried: e.Keys.Count, e.OldValues.Count, e.NewValues.Count -----------> all give zero Some said if TemplateField is used, e.Keys and Oldvalues, NewValues are all empty. Then what suppose to be used in such case? Thanks for any...
12
4851
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I want to plant an Easter Egg in our software. We have a TextBox that is multiline and used to display all sorts of messages on the screen for our operators based on database queries and such. The Easter Egg I want to create would send a dump of the data for a particular part number to the screen when a certain secret combination of characters is pressed. If it works out well, I can actually impliment it on our production floor.
0
9721
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
9602
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
10639
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
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10383
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6881
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
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
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
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.