G
Gerry Viator
Hi all,
Trying to relate copy's of two tables in another dataset so I can loop
through
MainDS
Basically i'm trying to copy the two datatables and then put them in a
global dataset.
I then need to loop through the dataset.
so how do I relate and copy two datatables into one datatable and then
filter through it?
something like this:
For icounter = 0 To .Rows.Count - 1
If .Rows(icounter).Item("ModuleOwner") =
GlobalModuleName Then
If .Rows(icounter).Item("EntryName") =
SelectedItem Then
If .Rows(icounter).Item("EntryType") =
"text" Then
ElseIf .Rows(icounter).Item("EntryType") =
"list" Then
ElseIf .Rows(icounter).Item("EntryType") =
"mtext" Then
ElseIf .Rows(icounter).Item("EntryType") =
"Date" Then
End If
End If
End If
Next
Dim StrEntryList As String = "Select * from EntryList order by
ModuleOwner"
Dim StrValueList As String = "Select * from ValueList order by EntryName"
EntryDataTable = (ReturnSQLlist(StrEntryList, True, "Running Entry SQL
Query.")).Tables(0)
ValueDataTable = (ReturnSQLlist(StrValueList, True, "Running Values SQL
Query for Entries.")).Tables(0)
Dim Tble1 As DataTable = EntryDataTable.Copy
Tble1 = MainDS.Tables.Add
Dim Tble2 As DataTable = ValueDataTable.Copy
Tble2 = MainDS.Tables.Add
Dim RelatedTables As New DataRelation("DsRelation",
Tble1.Columns("EntryName"), Tble2.Columns("EntryName"))
MainDS.Relations.Add(RelatedTables)
DataGrid1.DataSource = MainDS
Public Function ReturnSQLlist(ByVal StrQuery As String, ByVal Querytxt As
Boolean, ByVal Msg As String) As DataSet
Dim DS As New DataSet
Dim DA As New SqlDataAdapter
Dim Dt As New DataTable
Dim row As DataRow
Dim icounter As Integer
SQLConnection()
Dim SQLCmdlist As New SqlClient.SqlCommand
If Querytxt = True Then
SQLCmdlist.CommandType = CommandType.Text
SQLCmdlist.CommandText = StrQuery
Else
SQLCmdlist.CommandType = CommandType.StoredProcedure
End If
SQLCmdlist.Connection = SQLConn
SQLConn.Open()
DA.SelectCommand = SQLCmdlist
DA.Fill(DS)
SQLCmdlist.Connection.Close()
SQLCmdlist.Dispose()
ReturnSQLlist = DS
End Function
Trying to relate copy's of two tables in another dataset so I can loop
through
MainDS
Basically i'm trying to copy the two datatables and then put them in a
global dataset.
I then need to loop through the dataset.
so how do I relate and copy two datatables into one datatable and then
filter through it?
something like this:
For icounter = 0 To .Rows.Count - 1
If .Rows(icounter).Item("ModuleOwner") =
GlobalModuleName Then
If .Rows(icounter).Item("EntryName") =
SelectedItem Then
If .Rows(icounter).Item("EntryType") =
"text" Then
ElseIf .Rows(icounter).Item("EntryType") =
"list" Then
ElseIf .Rows(icounter).Item("EntryType") =
"mtext" Then
ElseIf .Rows(icounter).Item("EntryType") =
"Date" Then
End If
End If
End If
Next
Dim StrEntryList As String = "Select * from EntryList order by
ModuleOwner"
Dim StrValueList As String = "Select * from ValueList order by EntryName"
EntryDataTable = (ReturnSQLlist(StrEntryList, True, "Running Entry SQL
Query.")).Tables(0)
ValueDataTable = (ReturnSQLlist(StrValueList, True, "Running Values SQL
Query for Entries.")).Tables(0)
Dim Tble1 As DataTable = EntryDataTable.Copy
Tble1 = MainDS.Tables.Add
Dim Tble2 As DataTable = ValueDataTable.Copy
Tble2 = MainDS.Tables.Add
Dim RelatedTables As New DataRelation("DsRelation",
Tble1.Columns("EntryName"), Tble2.Columns("EntryName"))
MainDS.Relations.Add(RelatedTables)
DataGrid1.DataSource = MainDS
Public Function ReturnSQLlist(ByVal StrQuery As String, ByVal Querytxt As
Boolean, ByVal Msg As String) As DataSet
Dim DS As New DataSet
Dim DA As New SqlDataAdapter
Dim Dt As New DataTable
Dim row As DataRow
Dim icounter As Integer
SQLConnection()
Dim SQLCmdlist As New SqlClient.SqlCommand
If Querytxt = True Then
SQLCmdlist.CommandType = CommandType.Text
SQLCmdlist.CommandText = StrQuery
Else
SQLCmdlist.CommandType = CommandType.StoredProcedure
End If
SQLCmdlist.Connection = SQLConn
SQLConn.Open()
DA.SelectCommand = SQLCmdlist
DA.Fill(DS)
SQLCmdlist.Connection.Close()
SQLCmdlist.Dispose()
ReturnSQLlist = DS
End Function