473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

VB.NET/ADO.NET populating a dataset

JordanMartz
''' <summary>
''' Populates the DataGridView
''' </summary>
Private Sub PopulateDataGridView()
' Set the column header names.
userAccessGrid.ColumnCount = 5
userAccessGrid.RowsDefaultCellStyle.BackColor = Color.White
userAccessGrid.RowHeadersVisible = True
userAccessGrid.Name = "User Access Grid"
userAccessGrid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Raised
userAccessGrid.CellBorderStyle = DataGridViewCellBorderStyle.Raised
userAccessGrid.ColumnHeadersHeight = 20
' Initialize basic DataGridView properties.
userAccessGrid.Dock = DockStyle.Fill
userAccessGrid.BackgroundColor = Color.LightGray
userAccessGrid.BorderStyle = BorderStyle.Fixed3D
userAccessGrid.Columns(0).Name = "AccessLevelDescription"
userAccessGrid.Columns(0).DataPropertyName = "AccessLevelDescription"
userAccessGrid.Columns(0).Width = 40
userAccessGrid.Columns(0).HeaderText = "Access Level Description"
userAccessGrid.Columns(0).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.Columns(1).Name = "NoAccess"
userAccessGrid.Columns(1).DataPropertyName = "NoAccess"
userAccessGrid.Columns(1).Width = 40
userAccessGrid.Columns(1).HeaderText = "No Access"
userAccessGrid.Columns(1).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.Columns(2).Name = "ReadOnly"
userAccessGrid.Columns(2).DataPropertyName = "ReadOnly"
userAccessGrid.Columns(2).Width = 40
userAccessGrid.Columns(2).HeaderText = "Read Only"
userAccessGrid.Columns(2).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.Columns(3).Name = "NormalAccess"
userAccessGrid.Columns(3).DataPropertyName = "NormalAccess"
userAccessGrid.Columns(3).Width = 40
userAccessGrid.Columns(3).HeaderText = "Normal Access"
userAccessGrid.Columns(3).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.Columns(4).Name = "TotalAccess"
userAccessGrid.Columns(4).DataPropertyName = "TotalAccess"
userAccessGrid.Columns(4).Width = 40
userAccessGrid.Columns(4).HeaderText = "Total Access"
userAccessGrid.Columns(4).DefaultCellStyle.Font = New Font("Arial", 7, FontStyle.Regular)
userAccessGrid.SelectionMode = DataGridViewSelectionMode.CellSelect
userAccessGrid.MultiSelect = False
userAccessGrid.BackgroundColor = Color.LightBlue
userAccessGrid.ColumnHeadersDefaultCellStyle.Font = New Font("Arial", 8, FontStyle.Regular)
'--------------------------------------------------------------------------------------------
Dim appdesc_selectStatement As String = "Select access.level, pas_appitem FROM(access)Where access.uname = '' ORDER BY appitem"
Dim level_selectStatement As String = "Select accitem.appdesc, acclevels.level, accitem.appitem FROM(accitem, acclevels, access)Where access.uname = '' And accitem.appitem = access.appitem And access.level = acclevels.level Order By accitem.appitem"

Dim dt_Appdesc As New DataSet()
v = clsDataAnalyzerJetOleDb.MSAccessOleDb.PopulateData Set(appdesc_selectStatement)
Dim dt_Level As New DataSet()
dt_Level = clsDataAnalyzerJetOleDb.MSAccessOleDb.PopulateData Set(level_selectStatement)

Dim ds As DataSet = New DataSet()

Dim Dt_UserAccessDataSet As New DataSet()

Dim DescriptionColumns() As DataColumn = New DataColumn() {ds.Tables(0).Columns("appitem"), ds.Tables(0).Columns("appdesc")}
Dim AccessLevelColumns() As DataColumn = New DataColumn() {ds.Tables(1).Columns("level"), ds.Tables(1).Columns("desc")}
Dim Tran_Detail As New DataRelation("DescriptionColumns", ds.Tables(0).Columns("AccessLevelDescription"), AccessLevelColumns(1).Columns("No Access", "ReadOnly", "NormalAccess", "TotalAccess"))


'Dim tablearray() As DataTable = New DataTable(3) {}
'tablearray(0) = dt_Appdesc.Tables("appitem")
'tablearray(1) = mySecondDataSet.Tables("AnotherTable")
'tablearray(2) = myThirdDataSet.Tables(0)

'get a DataTableReader over these tables
'myDataTableReader = myFirstDataSet.GetDataReader(tablearray)

' Section for filling the Fields after the Data has been looped and read into the Grid
Dim OleDBConn As OleDbConnection = New OleDbConnection(MSAccessOleDb.ConnectionString())
OleDBConn.Open()

Dim cmd As OleDbCommand = New OleDbCommand("appdesc_selectStatement", dt_Appdesc)
Dim daTransactions As OleDbDataAdapter = New OleDbDataAdapter(cmd)
daTransactions.Fill(ds, "dt_Appdesc")

Dim cmdDetails As OleDbCommand = New OleDbCommand("level_selectStatement", dt_Level)
Dim daTransactionDetails As OleDbDataAdapter = New OleDbDataAdapter(cmdDetails)
daTransactionDetails.Fill(ds, "dt_Level")

DataRelations(Of String, DescriptionColumns(), AccessLevelColumns(), Boolean)()

Dim dx As New DataGridViewTextBoxColumn() = New DataGridViewTextBoxColumn()

'Pass in ds as DataSet, and "Transactions as TblName

Dim userAccessDataRow As DataRow = dt_Appdesc.NewRow()
Dim userAccessDataAdapter As New OleDbDataAdapter()
For Each userAccessDataRow As DataRow
Dim i As Integer
For i = 0 To dt_Appdesc.Rows.Count - 1
'Loop through Query B
'For each Row in DataTableB
For Each userAccessDataRow As DataRow In userAccessTable.Rows
'The level from the query associates to the proper checkbox in the row
accessQuery = accessQuery + 1
'Loop Through Query A's DataTable
i = 0
For Each userAccessDataRow In userAccessTable.Rows
userAccessTable.Columns(1)(0) = userAccessDataRow(0)(1).value
'i = i + 1 'So, that we continue looping
'Level2 = Row(0).value
'If Level2 = Level1 Then 'Set the level
CheckBox in Column(1)
Exit For
Exit For
Next
Next
Next
Next
Try
' Section for filling the Fields after the Data has been looped and read into the Grid
If dt_Appdesc.Rows.Count = 0 Then
Dim OleDBConn As OleDbConnection = New OleDbConnection(GetOleDBConn())
OleDBConn.Open()
userAccessDataAdapter.SelectCommand = New OleDbCommand(appdesc_selectStatement, OleDBConn)
userAccessDataAdapter.Fill(dt_Appdesc)
userAccessDataAdapter.InsertCommand = New OleDbCommandBuilder(userAccessDataAdapter).GetInse rtCommand()
userAccessDataRow("uname").Trim()
dt_Appdesc.Rows.Add(userAccessDataRow)
OleDBConn.Close()
OleDBConn.Dispose()
Else
Throw (New Exception("Error attempting to insert duplicate data."))
End If
Catch messerr As Exception
Call ShowErrorMessage(messerr, "listboxUserGroup_SelectedIndexChanged", "frm_security")
End Try
' Add the rows to the DataGridView.
Dim rows() As Object = {}
Dim rowArray As Object()
For Each rowArray In rows
userAccessGrid.Rows.Add(rowArray)
Next rowArray
' Adjust the row heights so that all content is visible.
userAccessGrid.AutoResizeRows(DataGridViewAutoSize RowsMode.AllCellsExceptHeaders)
End Sub


Here's my nasty 150 line DataSet, DataRelation, DataObject, DataBullshit problem. As you can tell, this isn't the first day that I've been working on this function. If you have any bones to through in my general direction, I'd be incredibly grateful. My goal is to get a two Datasets and combine them after I take the user access level and turn it sideways. Then populate the gridview, then I'm going to write back to the database from the selected values.

Gridview looks like
Appdesc NoAccess Read-Only Normal Total Access
blah blah X X X X
blah blah X X X X
Aug 21 '07 #1
0 3224

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Juan | last post by:
When populating a dataset I get an error if the data being retrieved includes a string field with a Null value: "Not valid store type: DBNull". What kinf of data type can i define in the dataset to...
0
by: amber | last post by:
I've been trying to figure out how to get 2 datasets to populate a report/subreport - and I think I'm on the right track...just having a few problems somewhere... I have created a dataset (.xsd)...
2
by: Janus | last post by:
Hello. I need a little advice for populating the treeview control. I dont want my application to hang while populating the treeview, there is a lot of data what's the best approach? Maybe...
2
by: Robert | last post by:
I'm sure this is a fairly basic question, but I've been looking all over the web for days for suggestions on how to do this. I've got a datagrid that's bound to a dataset on my form. It includes...
1
by: John | last post by:
Hi all, I have an interesting situation. I have a datagrid I'm currently populating using a dataset but now I need to introduce some extra records into this. I'm unsure of which method to use....
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
4
by: Paul | last post by:
I sometimes get a timeout error when populating my datagrid, the code is WizardConnection.Open() UpdateCommand.CommandText = "EXECUTE sp_assign_user '" & PhysOffice.SelectedValue & "', '" &...
3
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is...
6
by: p.mc | last post by:
Hi all, I have a MS SQLServer database which has two tables, 'images' and 'photographers'. The photographer table contains a field for PhotographerID and a one for PhotographerName. The image...
1
by: mike11d11 | last post by:
For some reason I'm getting no data populating in my crystal report. I built my crystal report off my dataset in my project, and I fill the dataset when opening the main form, and count the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.