Transferring data from one DataGridView to another - Tutoria

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
2 posts Page 1 of 1
Contributors
User avatar
Skillful
Skillful Coders
Skillful Coders
Posts: 969
Joined: Tue Nov 16, 2010 10:07 am

Hello guys.
Here is my new tutorial.
Hope you like it! :)

Ok lets start the tutorial now.

1. Open VB.NET and create a new Windows Forms Application.
2. Rename your Form to GridDemo.
3. Create One Database File named "DataBaseFile" in Microsoft SqlServer Management Studio Express.
4. Create any 1 Table in DatabaseFile.
5. Now come to the Windows Form.
6. Take Two DataGridView (named DataGridView1 & DataGridView2), One Button (named cmdShift) on the Form.
7. Go to the code view and delete all code and put this code -
Code: Select all
Imports System.Data.SqlClient

Public Class DataSetDemo

 Dim Conn As New SqlConnection("Data Source=Studio\SqlExpress; Initial Catalog= DataBaseFile;Integrated  Security=True")                               'Create new SqlConnection String
    Dim Dset As New DataSet()               'Create new Instance of DataSet Class
    Dim adapt As SqlDataAdapter          'Create new Instance of SqlDataAdapter Class
    Dim cmd As SqlCommand                  'Create new Instance of SqlCommand Class

Public Sub UpdateGrid()                      'Update the DataSource of DataGridView1 and DataGridView2    
        Dset.Clear()                                  'Clear the Dataset Contents

        adapt = New SqlDataAdapter("Select * from Information", Conn)
        adapt.Fill(Dset, "Information")                'Add the "Information" table to DataSet

'Display the content of "Information" table to DataGridView
        DataGridView1.DataSource = Dset.Tables("Information")  

        adapt = New SqlDataAdapter("Select * from Shift_Info", Conn)
        adapt.Fill(Dset, "Shift_Info")                  'Add the "Shift_Info" table to DataSet

'Display the content of "Shift_Info" table to DataGridView
        DataGridView2.DataSource = Dset.Tables("Shift_Info")     
    End Sub
Private Sub GridDemo_Load(ByVal sender As System.Object,  _
                                                               ByVal e As System.EventArgs) Handles MyBase.Load
                        UpdateGrid()
 End Sub

End Class
And you are done!! :D
Hope you liked my tutorial!
If you like my tutorial then please give me +rep! :)
Credits : VBDotNetHeaven
Instead of LOL use this -
LSIBMHBIWFETALOL

Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

Original Thread can be found at: (http://www.vbdotnetheaven.com/UploadFile/ea36c5/5867/ )
Created BY: Mayur Dighe March 02, 2011
Image
2 posts Page 1 of 1
Return to “Tutorials”