Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 03-03-2009
Member
 
Join Date: Feb 2009
Posts: 96
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.
Reply With Quote
  #2  
Old 03-03-2009
Member
 
Join Date: Mar 2008
Posts: 258
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
Reply With Quote
  #3  
Old 03-03-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
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
Reply With Quote
  #4  
Old 03-03-2009
Member
 
Join Date: Feb 2009
Posts: 96
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
Reply With Quote
  #5  
Old 03-03-2009
Member
 
Join Date: Feb 2009
Posts: 133
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?)
__________________
IF YOU CAN'T Convince THEM ...

CONFUSE THEM ...

Last edited by madjack : 03-03-2009 at 02:11 PM.
Reply With Quote
  #6  
Old 03-03-2009
Member
 
Join Date: Feb 2009
Posts: 96
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "how do i load data into an unbound datagridview"
Thread Thread Starter Forum Replies Last Post
How to auto load Meta data from Amazon? Tinku-Jia Windows Software 4 22-02-2012 10:00 PM
Unbound Sprint and Aim in Serious Sam 3: BFE Akshey Video Games 9 26-11-2011 12:05 PM
Value in unbound text box in DB restore Devabrata Software Development 6 11-01-2011 07:21 PM
Flash Lite 3.1 Unable to load data dilemma Harmony60 Portable Devices 4 20-04-2010 03:00 PM
Line Rider 2: Unbound game application issue Kaufman Video Games 5 30-03-2010 05:40 AM


All times are GMT +5.5. The time now is 10:07 AM.