Click here to Skip to main content
11,805,604 members (47,356 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB VB.NET
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
Edited 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 at 11-May-13 2:31am
thanks I'll give it a feedback :)
Mohammed Hameed at 11-May-13 2:32am
You're welcome!!! at 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 at 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
0 OriginalGriff 300
1 Richard Deeming 225
2 Sergey Alexandrovich Kryukov 170
3 ppolymorphe 125
4 CPallini 120
0 OriginalGriff 3,265
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2015
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