how do i load data into an unbound datagridview
how do i load data from a table into an unbound datagridview. All the research i've done 99% of doesnt show how to load from a table all it shows is how to add fields or information manually.
Example:
if i have form 1 with employee data and a employee table i use the id of the employee to search payroll records and only display that employees payroll record(s) on a 2nd form which is an unbound datagridview. The payroll records are also in a table... Can some one show code that would be similar to this.. and where would i put this said code---- Yeah I know I'm a noob but we all start somewhere.
Re: how do i load data into an unbound datagridview
To illustrate how to load MySQL data into the DataGridView control a simple VB.NET 2008 project was developed (Figure 1). As you can see, the form contains a DataGridView control with ten columns and two groups of bound and unbound data load buttons (Load 1 and Load 2). Both groups show the execution time in seconds (s) for 20,000 records of MySQL data load.
Figure 1: Bound and unbound DataGridView control project
look at the code of the buttons Load 1 (bound mode) and Load 2 (unbound mode). Listing 2 shows the click event code of the bound Load 1 button. The Using statement creates and destroys the instance of a class UnboundClass (Listing 3). The ADO.NET Connection String mMySQLConnectionString has been passed as a constructor to the class. Just a reminder that this Connection String value is defined and stored in the app.config file as I explained in the article "Define and Store MySQL ADO Connection String in VB.NET 2005". The procedure BoundDataLoading() (Listing 4) is called to load the data. The DataGridView UnboundDataGridView and the TexBox RecordCountTextBox are passed by reference. These procedures is showing below.
Code:
Private Sub BoundLoadButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles BoundLoadButton.Click
swatch.Reset()
swatch.Start()
Cursor = Cursors.WaitCursor
Try
Using BoundObject As New UnboundClass(mMySQLConnectionString)
Call BoundObject.BoundDataLoading(UnboundDataGridView, _
RecordCountTextBox, _
mErrorMsgString)
If Not IsNothing(mErrorMsgString) Then
Cursor = Cursors.Default
MessageBox.Show(mErrorMsgString, _
Me.Text, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End If
End Using
Catch exError As Exception
MessageBox.Show(exError.Message, _
Me.Text, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
Cursor = Cursors.Default
swatch.Stop()
mTimeDouble = swatch.ElapsedMilliseconds * 0.001
BoundTimeTextBox.Text = mTimeDouble.ToString
End Sub
Re: how do i load data into an unbound datagridview
Private Sub BoundLoadButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles BoundLoadButton.Click
swatch.Reset()
swatch.Start()
Cursor = Cursors.WaitCursor
Try
Using BoundObject As New UnboundClass(mMySQLConnectionString)
Call BoundObject.BoundDataLoading(UnboundDataGridView, _
RecordCountTextBox, _
mErrorMsgString)
If Not IsNothing(mErrorMsgString) Then
Cursor = Cursors.Default
MessageBox.Show(mErrorMsgString, _
Me.Text, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End If
End Using
Catch exError As Exception
MessageBox.Show(exError.Message, _
Me.Text, _
MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Try
Cursor = Cursors.Default
swatch.Stop()
mTimeDouble = swatch.ElapsedMilliseconds * 0.001
BoundTimeTextBox.Text = mTimeDouble.ToString
End Sub
Re: how do i load data into an unbound datagridview
ty for the try but once again that just shows how to show info on the same form as the button--- i have 2 forms and my 2nd form is NOT bound to the 1st form. the 1st form has all the bound information to the employees but the payroll itself is NOT bound. I need to search the employee records and on selecting the employee a 2nd form opens showing the payroll--- 2 forms in total not one-- the above code only works for single form apps. reason is the sql string doesnt carry to the 2nd form
Re: how do i load data into an unbound datagridview
Hi, Daren!
I think this is what you need to look for loading data to an unbound datagrid view!
http://dev.mysql.com/tech-resources/...t.html#Unbound
AND
http://www.evisualwww.com/downloads/...plications.pdf
I hope this helps you loading data to your unbound datagrid in the second form
Just a question - Why do you want this second form? (Is it important?)
Re: how do i load data into an unbound datagridview
yeah madjack its for a school project--- they state it must be on a second form