-
Nov 18th, 2009, 12:09 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to get set of values in one msgbox
This piece of code is returning the multiple values of Category in MsgBox one by one. How can i make it to show all the values of category in one MsgBox separated by commas and store it in a String?
Code:
Try
Using connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ProjectMW\MachineWale\MachineWale\DatabaseMW.mdf;Integrated Security=True;User Instance=True")
connection.Open()
Using command As New SqlCommand("SELECT * FROM MachineProfile where ClientID = '" & MDIParentMW.clid & "'", connection)
Using reader As SqlDataReader = command.ExecuteReader()
If reader.HasRows Then
While reader.Read()
MsgBox(reader("Category"))
End While
Else
End If
End Using
End Using
connection.Close()
End Using
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Exclamation)
End Try
-
Nov 18th, 2009, 12:15 AM
#2
Re: How to get set of values in one msgbox
If I have understood your query correctly then Declare a new String Variable and keep on appending the values of Category in the loop separated by appropriate delimiter to it and then when you exit the loop simply display the string variable in the message box.
Edit:
Here is a very basic example...
Code:
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim StrSample As String, i As Long
StrSample = ""
For i = 1 To 5
If i = 1 Then
StrSample = i
Else
StrSample = StrSample & " , " & i
End If
Next i
'~~> Display String
MsgBox(StrSample)
End Sub
End Class
Last edited by Siddharth Rout; Nov 18th, 2009 at 12:21 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Nov 18th, 2009, 12:57 AM
#3
Thread Starter
Hyperactive Member
Re: How to get set of values in one msgbox
I have modified you suggestion and tried using it as below. But i am not getting the desired result. What could possibly be wrong in here?
vb Code:
Try Using connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ProjectMW\MachineWale\MachineWale\DatabaseMW.mdf;Integrated Security=True;User Instance=True") connection.Open() Using command As New SqlCommand("SELECT Count(MachineID) as NoMach FROM MachineProfile where ClientID = '" & MDIParentMW.clid & "'", connection) Using reader As SqlDataReader = command.ExecuteReader() While reader.Read() i = reader.Item("NoMach") End While End Using End Using connection.Close() End Using Using connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ProjectMW\MachineWale\MachineWale\DatabaseMW.mdf;Integrated Security=True;User Instance=True") connection.Open() Using command As New SqlCommand("SELECT * FROM MachineProfile where ClientID = '" & MDIParentMW.clid & "'", connection) Using reader As SqlDataReader = command.ExecuteReader() For j = 1 To i reader.Read() If j = 1 Then mach = reader("Category") Else mach = mach & "," & j End If Next j MsgBox(mach) End Using End Using connection.Close() End Using Catch ex As Exception MsgBox(ex.ToString, MsgBoxStyle.Exclamation) End Try
-
Nov 18th, 2009, 12:58 AM
#4
Thread Starter
Hyperactive Member
Re: How to get set of values in one msgbox
Is there a simpler way to get an array assigned to a string?
-
Nov 18th, 2009, 02:28 AM
#5
Re: How to get set of values in one msgbox
No you are not looping. and adding the correct value.
you are adding j which is similar to what I have done above but it was specific for that example...
mach = mach & "," & reader("Category")
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Nov 18th, 2009, 03:23 AM
#6
Thread Starter
Hyperactive Member
Re: How to get set of values in one msgbox
-
Nov 18th, 2009, 04:36 AM
#7
Re: [RESOLVED] How to get set of values in one msgbox
Try this:
vb.net Code:
Dim categoryList As New List(Of String) Using connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=D:\ProjectMW\MachineWale\MachineWale\DatabaseMW.mdf;Integrated Security=True;User Instance=True") connection.Open() Using command As New SqlCommand("SELECT * FROM MachineProfile where ClientID = '" & MDIParentMW.clid & "'", connection) Using reader As SqlDataReader = command.ExecuteReader() While reader.Read categoryList.Add(reader("Category")) End While MsgBox(Join(categoryList.ToArray, ",")) End Using End Using connection.Close() End Using
-
Nov 18th, 2009, 05:57 AM
#8
Thread Starter
Hyperactive Member
Re: [RESOLVED] How to get set of values in one msgbox
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|