Question Problem with datagrid display

dgcarter1949

New member
Joined
Mar 2, 2011
Messages
2
Programming Experience
1-3
Using the following code:

ds.Clear()
Dim da As New SqlDataAdapter(querystring, conn)
conn.ConnectionString = cs
da.TableMappings.Add("Table", tableName)
MessageBox.Show(querystring)
conn.Open()
da.Fill(ds)
conn.Close()
MessageBox.Show(tableName)
If tableName = "Users" Then
'code to diaplay grid
DataGridDataDisplay.DataSource = ds.Tables(0)
DataGridDataDisplay.Columns.Add("ID", "ID")
DataGridDataDisplay.Columns.Add("Title", "Title")
DataGridDataDisplay.Columns.Add("FirstName", "First Name")
DataGridDataDisplay.Columns.Add("LastName", "Last Name")
DataGridDataDisplay.Columns.Add("Address1", "Address")
DataGridDataDisplay.Columns.Add("PostCode", "Post Code")
DataGridDataDisplay.Columns.Add("DateOfBirth", "Date of Birth")
DataGridDataDisplay.Columns.Add("Phone", "Phone")
DataGridDataDisplay.Columns.Add("Mobile", "Mobile")
DataGridDataDisplay.Visible = True

ElseIf tableName = "Staff" Then
'code to display grid
DataGridDataDisplay.DataSource = ds.Tables(0)
DataGridDataDisplay.Columns.Add("ID", "ID")
DataGridDataDisplay.Columns.Add("[First Name]", "First Name")
DataGridDataDisplay.Columns.Add("[Last Name]", "Last name")
DataGridDataDisplay.Columns.Add("Position", "Position")
DataGridDataDisplay.Columns.Add("Address1", "Address")
DataGridDataDisplay.Columns.Add("PostCode", "Post Code")
DataGridDataDisplay.Columns.Add("Phone", "Phone")
DataGridDataDisplay.Columns.Add("Mobile", "Mobile")
DataGridDataDisplay.Visible = True

ElseIf tableName = "Courses" Then
'code to display grid

End If

End Sub

I am writing a search form to display a data grid where the content varies depending on whether the search form was called from an Add Staff form or an Add user form. However, regardless of which form calls the search form, the datagrid displays the Staff version of the columns.

Can anyone help with any suggestions?
 
Back
Top