Arranging data reading in from a database

I need to display names in the format: "Surname, First name"

Page 1 of 1

3 Replies - 879 Views - Last Post: 09 January 2009 - 10:50 AM Rate Topic: -----

#1 McMahon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 09-January 09

Arranging data reading in from a database

Post icon  Posted 09 January 2009 - 08:42 AM

Private Sub frmAttendace51_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		'clear data set of any existing data
		objDataSet.Clear()
		'fill schema
		objStudentDA.FillSchema(objDataSet, SchemaType.Source, "tblStudent")
		'fill data set with info from data adapter
		objStudentDA.Fill(objDataSet, "tblStudent")

		'fill the data set with info from tblClass
		objClassDA.FillSchema(objDataSet, SchemaType.Source, "tblClass")
		objClassDA.Fill(objDataSet, "tblClass")

		'fill the data set with info from tblClass
		objAttendanceDA.FillSchema(objDataSet, SchemaType.Source, "tblAttendance")
		objAttendanceDA.Fill(objDataSet, "tblAttendance")

		'setup the relationship
		objDataSet.Relations.Clear()
		objDataSet.Relations.Add("Class2Student", _
								 objDataSet.Tables("tblClass").Columns("ClassID"), _
								 objDataSet.Tables("tblStudent").Columns("ClassID"))
		objDataSet.Relations.Add("Student2Attendance", _
								 objDataSet.Tables("tblStudent").Columns("StudentID"), _
								 objDataSet.Tables("tblAttendance").Columns("StudentID"))

		lstStudents51.Items.Clear()

[b]		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[/b]

		lstStudents51.SelectedIndex = 0

This post has been edited by McMahon: 09 January 2009 - 09:10 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Arranging data reading in from a database

#2 jjsaw5   User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 3,063
  • Joined: 04-January 08

Re: Arranging data reading in from a database

Posted 09 January 2009 - 09:22 AM

When you are making a post you are going to need to provide us with some information about your code in the post. Not in the heading of the post.


Things you need to include, error messages, what is the code supposed to do that it currently isn't.

Remeber the more information you can provide us with the better we are able to help you.
Was This Post Helpful? 0
  • +
  • -

#3 McMahon   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 09-January 09

Re: Arranging data reading in from a database

Posted 09 January 2009 - 09:30 AM

Data (firstname and surname) is being read in from my database and being displayed in a listbox. It is being displayed in a big long list.

The code I have provided so far is error free, I just would like to know what to add to it so I can display the data in the listbox as Surname, Firstname i.e. Bloggs, Joe. The way it is now in the list box is:
Bloggs
Joe

This post has been edited by McMahon: 09 January 2009 - 09:30 AM

Was This Post Helpful? 0
  • +
  • -

#4 dklingman   User is offline

  • D.I.C Regular
  • member icon

Reputation: 33
  • View blog
  • Posts: 263
  • Joined: 23-December 08

Re: Arranging data reading in from a database

Posted 09 January 2009 - 10:50 AM

		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)
			lstStudents51.Items.Add(strSurname + ", " + strFirstname)
		Next


This post has been edited by dklingman: 09 January 2009 - 10:50 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1