Ernesto
asked on
Get values Vb.Net
Need to read 2 values from a query in vb.net
this one get me only pagadot that i asign to valor
how to get nombre in the same
what is the way dear experts
cn.Open()
Dim nusa15 As String = "SELECT pagadot,nombre FROM cheque WHERE id = '" & CustomerId & "'"
Dim cmd15 As New OleDbCommand(nusa15, cn)
valor = (cmd15.ExecuteScalar())
cn.Close()
this one get me only pagadot that i asign to valor
how to get nombre in the same
what is the way dear experts
ASKER
so the way for retrive that is use multiple querys?
Something like this:
OleDbDataReader reader = cmd15.ExecuteReader();
reader.Read()
reader.getInt32(0) ' pagout
reader.getString(1) ' nombre
>>so the way for retrive that is use multiple querys?
No. As jcgd posted and from the example in the link I posted, use a DataReader not ExecuteScalar.
No. As jcgd posted and from the example in the link I posted, use a DataReader not ExecuteScalar.
Are you using Access or SQL Server?
Sample:
Private Sub FineData()
Dim mySQLDataAdapter as SQLDataAdapter = nothing
Dim DS as dataset = nothing
Dim sTableName as string = "cheque "
Dim str as string = nothing
cn.Open()
Try
str = "SELECT pagadot,nombre "
str &= "FROM " & sTableName & " "
str &= "WHERE id = CustomerId "
If cn.State <> Data.ConnectionState.Open Then cn.Open()
mySQLDataAdapter = New SqlDataAdapter(str, myConn) 'FOR SQL Server
mySQLDataAdapter.Fill(DS)
PopulateSupplierListFromDS (DS)
Catch Exp As DataException
MsgBox("FillDataSet Procedure Error", MsgBoxStyle.Critical, "Load Data Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error in Cheque Table")
Finally
str = Nothing
If cn.State <> ConnectionState.Closed Then cn.Close()
End Try
End Sub
IF need you can add a join if you are looking at more than one table.
Private Sub FineData()
Dim mySQLDataAdapter as SQLDataAdapter = nothing
Dim DS as dataset = nothing
Dim sTableName as string = "cheque "
Dim str as string = nothing
cn.Open()
Try
str = "SELECT pagadot,nombre "
str &= "FROM " & sTableName & " "
str &= "WHERE id = CustomerId "
If cn.State <> Data.ConnectionState.Open Then cn.Open()
mySQLDataAdapter = New SqlDataAdapter(str, myConn) 'FOR SQL Server
mySQLDataAdapter.Fill(DS)
PopulateSupplierListFromDS
Catch Exp As DataException
MsgBox("FillDataSet Procedure Error", MsgBoxStyle.Critical, "Load Data Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error in Cheque Table")
Finally
str = Nothing
If cn.State <> ConnectionState.Closed Then cn.Close()
End Try
End Sub
IF need you can add a join if you are looking at more than one table.
The SQL posted appears to be returning a single row. Personally, I wouldn't bother with a DataAdapter, DataSet and DataTable for one row. Too much overhead for what is needed.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
I would use a DataReader:
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/retrieving-data-using-a-datareader
You "could" concatenate the values inside the select to return them as a single value for ExecuteScalar but I wouldn't recommend it. I only mention it because I'm sure someone else will.