vb.netdatatablerequestoledboraclecommand

Return rows from multiple requests with datatable vb.net


If I have two or more queries in the same command:

Using myCommand As New OracleCommand(
"select value from table where id between 1 and 3;" & 
"select value1 from table where id = 1000", DBSettings.GetConnection())

and I have DataTable which select the values from the first request

Dim dt As DataTable = New DataTable
dt.Load(myCommand.ExecuteReader)

value1 = dt.Rows(0).Item(0).ToString().Trim()
value2 = dt.Rows(1).Item(0).ToString().Trim()
value3 = dt.Rows(2).Item(0).ToString().Trim()

Can I get values throuth DataTable from second request? Is it possible, that my values get the rows from the following requests?

I do not want to create a a lot of commands and DataTable, because I have a lot of commands and the values that I need to initialize


Solution

  • Do a UNION. It will combine two query into one result set.

    select value from table where id between 1 and 3
    UNION
    select value1 from table where id = 1000;
    

    Here's the same query with the new information from your question

    SELECT SYSPARM_VAL2 FROM SMS_PARM WHERE SYSPARM_ID BETWEEN 9900029 AND 9900033
    UNION
    SELECT SYSPARM_VAL4 FROM SMS_PARM WHERE SYSPARM_ID = 9900030;