SonicBoomAu
Well-known member
Hi All,
Am unsure If I am doing this correctly.
I have a Access DB, I have 2 Tables (StaticAssets) & (IssuedAssets). Static Assets contains all the Assets Details (i.e AssetNo, Equip0, Ser0, Qty0, Type, Classification, SystemName, OS, etc) Issued Assets contains all the info from StaticAssets plus the Issued information (i.e. SigneeName, CourseName, CourseDates, SigneeWing, SignOutDate). Issued Asset contains only the Assets that are issued out.
What I am trying to do is list all the Static Assets in a datagrid, (No Problems There). If any of those assets are Issued then have a plus sign and display the issued info.
Heres my Code so far.
[VB]
Set strDatabaseName
strDatabaseName = "LocationofDB"
Dim cnAdoNetConnection As New OleDb.OleDbConnection
Dim cCommand As New OleDb.OleDbCommand
Dim daDataAdapter As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim strSqlQuery As String
Dim strSqlQuery1 As String
Dim strSqlQuery2 As String
Dim strSqlQuery3 As String
strSqlQuery = "AssetNo, Equip0, Ser0, Qty0, Type, Classification, SystemName, OS"
strSqlQuery1 = "SELECT " & strSqlQuery & " From StaticAssets"
strSqlQuery2 = "AssetNo, SigneeName, CourseName, CourseDates, SigneeWing, SignOutDate"
strSqlQuery3 = "SELECT " & strSqlQuery2 & " From IssuedAssets"
Try
Open the connection to the database
cnAdoNetConnection.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
strDatabaseName
cnAdoNetConnection.Open()
Retrieve all the Permanent Asset Information
daDataAdapter = New OleDb.OleDbDataAdapter(strSqlQuery1, cnAdoNetConnection)
daDataAdapter.Fill(ds, "StaticAssets")
cCommand.CommandText = strSqlQuery3
daDataAdapter.Fill(ds, "IssuedAssets")
Dim rel As New DataRelation("View Issued Assets", _
ds.Tables("StaticAssets").Columns("AssetNo"), _
ds.Tables("IssuedAssets").Columns("AssetNo"))
ds.Relations.Add(rel)
DataGrid1.DataSource = ds.Tables("StaticAssets")
Close the connection to the database
cnAdoNetConnection.Close()
Catch ex As Exception
MessageBox.Show("An error has occurred! Error: " & ex.Message, _
"DIntTC Asset Management", MessageBoxButtons.OK, MessageBoxIcon.Error)
Close the connection to the database
cnAdoNetConnection.Close()
End Try
[/VB]
The staticassets info displays in the daatagrid. But all the Assets have plus signs when only 3 are currently Issued. And when you navigate down it displays the same information not the information I require (strSqlQuery2).
Please Help.
Am unsure If I am doing this correctly.
I have a Access DB, I have 2 Tables (StaticAssets) & (IssuedAssets). Static Assets contains all the Assets Details (i.e AssetNo, Equip0, Ser0, Qty0, Type, Classification, SystemName, OS, etc) Issued Assets contains all the info from StaticAssets plus the Issued information (i.e. SigneeName, CourseName, CourseDates, SigneeWing, SignOutDate). Issued Asset contains only the Assets that are issued out.
What I am trying to do is list all the Static Assets in a datagrid, (No Problems There). If any of those assets are Issued then have a plus sign and display the issued info.
Heres my Code so far.
[VB]
Set strDatabaseName
strDatabaseName = "LocationofDB"
Dim cnAdoNetConnection As New OleDb.OleDbConnection
Dim cCommand As New OleDb.OleDbCommand
Dim daDataAdapter As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim strSqlQuery As String
Dim strSqlQuery1 As String
Dim strSqlQuery2 As String
Dim strSqlQuery3 As String
strSqlQuery = "AssetNo, Equip0, Ser0, Qty0, Type, Classification, SystemName, OS"
strSqlQuery1 = "SELECT " & strSqlQuery & " From StaticAssets"
strSqlQuery2 = "AssetNo, SigneeName, CourseName, CourseDates, SigneeWing, SignOutDate"
strSqlQuery3 = "SELECT " & strSqlQuery2 & " From IssuedAssets"
Try
Open the connection to the database
cnAdoNetConnection.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
strDatabaseName
cnAdoNetConnection.Open()
Retrieve all the Permanent Asset Information
daDataAdapter = New OleDb.OleDbDataAdapter(strSqlQuery1, cnAdoNetConnection)
daDataAdapter.Fill(ds, "StaticAssets")
cCommand.CommandText = strSqlQuery3
daDataAdapter.Fill(ds, "IssuedAssets")
Dim rel As New DataRelation("View Issued Assets", _
ds.Tables("StaticAssets").Columns("AssetNo"), _
ds.Tables("IssuedAssets").Columns("AssetNo"))
ds.Relations.Add(rel)
DataGrid1.DataSource = ds.Tables("StaticAssets")
Close the connection to the database
cnAdoNetConnection.Close()
Catch ex As Exception
MessageBox.Show("An error has occurred! Error: " & ex.Message, _
"DIntTC Asset Management", MessageBoxButtons.OK, MessageBoxIcon.Error)
Close the connection to the database
cnAdoNetConnection.Close()
End Try
[/VB]
The staticassets info displays in the daatagrid. But all the Assets have plus signs when only 3 are currently Issued. And when you navigate down it displays the same information not the information I require (strSqlQuery2).
Please Help.