Note that there are some explanatory texts on larger screens.

plurals
  1. POdataTable as parameter to Function
    text
    copied!<p>I have SQL SP's that I use to populate DataTables in VB and those to fill listbox/charts etc in VB form. In VB I am trying to use OOP and thus use classes for variables. In VB I have a function with the code to pull the data using a SP, this function I want to use everytime I pull data, so with every different data request you send different inputs, parameters to the function.</p> <p>I can achieve this for input parameters which are of integer data type, however I am stuck with doing the same for DataTable type. If I can I would like to use the same DataTable, but when you run the function again to fill another container(listbox, then chart etc) the first container loses it's data and is empty, since the DataTable is loaded with new data. This is ofcourse after the first dataset has been used to fill the first container. Which leads me to thinking the DataTable has a "permanent" link to the container to keep it populated?</p> <p>This led me to trying to declare multiple DataTables and passing a different one for every container. Here I get the problem to declare and pass DataTable type. Any solution to this problem? Another question is, is it possible to have a DataTable class?? I use MS SQL Server 2012 &amp; MS Visual Studio 2010.</p> <p>This is how my function to fill a DataTable looks:</p> <pre><code>Public Function outputData(ByVal beg_Date, ByVal end_Date, ByVal ID1, ByVal proC, ByRef dDataTable) If conn.State = ConnectionState.Open Then pData.Clear() SQLcomm = New SqlClient.SqlCommand(proC, conn) SQLcomm.CommandType = CommandType.StoredProcedure SQLcomm.Parameters.AddWithValue("@begDate", SqlDbType.Date).Value = beg_Date SQLcomm.Parameters.AddWithValue("@endDate", SqlDbType.Date).Value = end_Date SQLcomm.Parameters.AddWithValue("@ID1", SqlDbType.Int).Value = ID1 aDapter.SelectCommand = SQLcomm aDapter.Fill(dDataTable) Return pData End Function </code></pre> <p>proC is the SQL procedure parameter, dDataTable the DataTable parameter. Any tips will be appreciated.</p> <p>Thank you,</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload