Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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)
            condb.Open()
            Using cmd As MySqlCommand = condb.CreateCommand
                cmd.CommandText = SQL
                Using sqlAdapter As New MySqlDataAdapter(SQL, condb)
                    sqlAdapter.Fill(ds)                    
                End Using
            End Using
            condb.Close()
        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 20:08pm
Edited 10-May-13 20:28pm
v3

1 solution

Rate this: bad
good
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;
        }
  Permalink  
Comments
iMaker.ph at 11-May-13 2:31am
   
thanks I'll give it a feedback :)
Mohammed Hameed at 11-May-13 2:32am
   
You're welcome!!!
iMaker.ph 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 Mathew Soji 334
1 Maciej Los 295
2 BillWoodruff 290
3 Afzaal Ahmad Zeeshan 257
4 DamithSL 205
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,045


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2014
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