Click here to Skip to main content
13,044,467 members (119,911 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi I've used this code for so long

Public Sub ShowDataTable(Optional ByVal field As String = "*", Optional ByVal range As String = Nothing)
    SQL = "CALL Phonedb.MyPhonebook('" & field & "','" & range & "')"
    Dim ds As New DataSet
    Using condb As New MySqlConnection(con)
        Using cmd As MySqlCommand = condb.CreateCommand
            cmd.CommandText = SQL
            Using sqlAdapter As New MySqlDataAdapter(SQL, condb)
            End Using
        End Using
    End Using
    DTG.DataSource = ds.Tables(0)
End Sub

and I wan't to try to make it as a Class/sub
my quest is how can i Pass datagridview on a function/sub and return it ?

adding parameters on a Sub is my problem

Public Sub ShowDataTable(ByVal STRD As String, ByVal conStr As String)
Posted 10-May-13 19:08pm
Updated 10-May-13 19:28pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There is a class called DataGrid, which you can use as a type to send in you method as a parameter and also you can return the same. I'm not much familiar with the VB but anyhow I have given example method in C#, which would obviously can help u to implement the same in VB.

public DataGrid SomeMethod(DataGrid dg)
            DataGrid grid = new DataGrid();
            grid.AllowPaging = true;
            return grid;
Comments 11-May-13 2:31am
thanks I'll give it a feedback :)
Mohammed Hameed 11-May-13 2:32am
You're welcome!!! 11-May-13 2:41am
how Can I implement your code ?

if I add dg as datagrid it says that Datagrid is not define.
Mohammed Hameed 11-May-13 2:47am
Note that 'dg' is parameter of type DataGrid, which you need pass to this method from the calling code. This is like input (existing grid name you are using in ur app) for the method.

Note: DataGrid class for data grid and GridView class for grid view. You have to use the class as per your control accordingly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100