VB.NET - manipulating data coming in from a database - Help

VB.NET - manipulating data coming in from a database - Help

Post by Laur » Sat, 10 Jan 2009 20:55:50



Hi,

I have a database, one table contains a field "FName" and a field
"SName".
I can successfully read the FName and the SName into my application.
However, I need to get them to read in, in the format: SName,FName as
currently I can only get them to come in seperately. How can I do
this? (the surnames and first names are being read into a listbox)

Thanks.

(below is the code I have so far)
        lstStudents51.Items.Clear()

        Dim i As Integer
        Dim strSurname As String
        Dim strFirstName As String
        For i = 1 To objDataSet.Tables("tblStudent").Rows.Count
            strSurname = objDataSet.Tables("tblStudent").Rows(i -
1).Item("SName")
            strFirstName = objDataSet.Tables("tblStudent").Rows(i -
1).Item("FName")
            lstStudents51.Items.Add(strSurname)
            lstStudents51.Items.Add(strFirstName)

        Next

        lstStudents51.SelectedIndex = 0

 
 
 

VB.NET - manipulating data coming in from a database - Help

Post by Cerebru » Sun, 11 Jan 2009 03:21:49


Why not simply append the last name and first name and then add to the
listbox ?

---
lstStudents51.Items.Add(strSurname & ", " & strFirstName)
---


Quote:> Hi,

> I have a database, one table contains a field "FName" and a field
> "SName".
> I can successfully read the FName and the SName into my application.
> However, I need to get them to read in, in the format: SName,FName as
> currently I can only get them to come in seperately. How can I do
> this? (the surnames and first names are being read into a listbox)

> Thanks.

> (below is the code I have so far)
> ? ? ? ? lstStudents51.Items.Clear()

> ? ? ? ? Dim i As Integer
> ? ? ? ? Dim strSurname As String
> ? ? ? ? Dim strFirstName As String
> ? ? ? ? For i = 1 To objDataSet.Tables("tblStudent").Rows.Count
> ? ? ? ? ? ? strSurname = objDataSet.Tables("tblStudent").Rows(i -
> 1).Item("SName")
> ? ? ? ? ? ? strFirstName = objDataSet.Tables("tblStudent").Rows(i -
> 1).Item("FName")
> ? ? ? ? ? ? lstStudents51.Items.Add(strSurname)
> ? ? ? ? ? ? lstStudents51.Items.Add(strFirstName)

> ? ? ? ? Next

> ? ? ? ? lstStudents51.SelectedIndex = 0


 
 
 

VB.NET - manipulating data coming in from a database - Help

Post by Harika medikond » Fri, 16 Jan 2009 15:52:51


You cna add this  code

 For i = 1 To objDataSet.Tables("tblStudent").Rows.Count
           strfullname = objDataSet.Tables("tblStudent").Rows(i -
1).Item("SName") & " " &  objDataSet.Tables("tblStudent").Rows(i -
1).Item("FName")
                     lstStudents51.Items.Add(strfullname )

       Next


> Hi,

> I have a database, one table contains a field "FName" and a field
> "SName".
> I can successfully read the FName and the SName into my application.
> However, I need to get them to read in, in the format: SName,FName as
> currently I can only get them to come in seperately. How can I do
> this? (the surnames and first names are being read into a listbox)

> Thanks.

> (below is the code I have so far)
>        lstStudents51.Items.Clear()

>        Dim i As Integer
>        Dim strSurname As String
>        Dim strFirstName As String
>        For i = 1 To objDataSet.Tables("tblStudent").Rows.Count
>            strSurname = objDataSet.Tables("tblStudent").Rows(i -
> 1).Item("SName")
>            strFirstName = objDataSet.Tables("tblStudent").Rows(i -
> 1).Item("FName")
>            lstStudents51.Items.Add(strSurname)
>            lstStudents51.Items.Add(strFirstName)

>        Next

>        lstStudents51.SelectedIndex = 0

 
 
 

VB.NET - manipulating data coming in from a database - Help

Post by Brandon Betance » Fri, 16 Jan 2009 22:36:27


Okham's Razor. Go with Cerebrus' answer.
 
 
 

VB.NET - manipulating data coming in from a database - Help

Post by Cerebru » Sat, 17 Jan 2009 03:17:27


Thanks, Brandon... I was unaware of that term. I just learned
something new :

http://en.wikipedia.org/wiki/Occam's_razor

"Lex parsimoniae", brother ! ;-)


Quote:> Okham's Razor. Go with Cerebrus' answer.

 
 
 

VB.NET - manipulating data coming in from a database - Help

Post by Brandon Betance » Sat, 17 Jan 2009 04:38:49


Yep. Simplest solution is usually the best.
 
 
 

VB.NET - manipulating data coming in from a database - Help

Post by Peter Smit » Sat, 17 Jan 2009 06:55:33


Does VB.Net let you get at String.Format?

 
 
 

VB.NET - manipulating data coming in from a database - Help

Post by Kaarthik Padmanabha » Sat, 17 Jan 2009 09:02:34


Yes it does.
String.Format("{0}, {1}", strSurname, strFirstName)


> Does VB.Net let you get at String.Format?

--
Kaarthik,
http://coding-passion.blogspot.com