VB.NET CONSULTA NO BD E GUARDAR RESULT EM VARIAVEL
como faz para guardar o valor de uma consulta no bd acces em uma variável.?
1° eu faço a consulta
Dim Consultaestoque As String = [Ô]Select 1 FROM BDPROD Where Quantidade Em Estoque = @Estoque[Ô]
e depois como faço para guarda o resultado em uma variavel privada?
1° eu faço a consulta
Dim Consultaestoque As String = [Ô]Select 1 FROM BDPROD Where Quantidade Em Estoque = @Estoque[Ô]
e depois como faço para guarda o resultado em uma variavel privada?
Public dr As SqlDataReader
Public selectText As String
Public myCommand As SqlCommand
Public ds As DataSet = New DataSet()
Public ConnectionString As String = [Ô]Data Source = [Ô] + strServidor + [Ô]; Initial Catalog = [Ô] + strBanco + [Ô]; User Id =[Ô] + strUsuarioBanco + [Ô]; Password =[Ô] + strSenhaUsuarioBanco
Public strConn As SqlConnection
Dim MINHAVARIAVEL as String=string.empty
[ô]SQL
strConn = New SqlConnection(ConnectionString)
strConn.Open()
selectText = [Ô]SELECT * FROM TABELA[Ô]
myCommand = New SqlCommand(selectText, strConn)
dr = myCommand.ExecuteReader()
While (dr.Read())
MINHAVARIAVEL=(dr([Ô]CAMPO_SQL[Ô]).ToString)
End While
strConn.Close()
Public selectText As String
Public myCommand As SqlCommand
Public ds As DataSet = New DataSet()
Public ConnectionString As String = [Ô]Data Source = [Ô] + strServidor + [Ô]; Initial Catalog = [Ô] + strBanco + [Ô]; User Id =[Ô] + strUsuarioBanco + [Ô]; Password =[Ô] + strSenhaUsuarioBanco
Public strConn As SqlConnection
Dim MINHAVARIAVEL as String=string.empty
[ô]SQL
strConn = New SqlConnection(ConnectionString)
strConn.Open()
selectText = [Ô]SELECT * FROM TABELA[Ô]
myCommand = New SqlCommand(selectText, strConn)
dr = myCommand.ExecuteReader()
While (dr.Read())
MINHAVARIAVEL=(dr([Ô]CAMPO_SQL[Ô]).ToString)
End While
strConn.Close()
Desculpa mais eu n sei mexer com sql. Como ficaria esse código para Access? obg pela atenção..
é a mesmo coisa só vai mudar o conector ...
Public StringDeConexao As String = String.Empty
Public Con As OleDb.OleDbConnection
Public Adap As OleDb.OleDbDataAdapter
Public Cmd As OleDb.OleDbCommand
Public Dt As DataSet
Public dr As OleDb.OleDbDataReader = Nothing
Public selectText As String = [Ô][Ô]
Public myCommand As OleDb.OleDbCommand = Nothing
Public ConnectionString As String = [Ô]Provider=Microsoft.Ace.Oledb.12.0; Data Source=[Ô] & Application.StartupPath & [Ô]\BancoDados.accdb;[Ô]
Public strConn As OleDb.OleDbConnection
strConn = New OleDb.OleDbConnection(ConnectionString)
strConn.Open()
selectText =[Ô]SELECT * FROM TABELA[Ô]
myCommand = New OleDb.OleDbCommand(selectText, strConn)
dr = myCommand.ExecuteReader()
While (dr.Read())
MINHAVARIAVEL=(dr([Ô]CAMPO_SQL[Ô]).ToString)
End While
strConn.Close()
Return True
Public StringDeConexao As String = String.Empty
Public Con As OleDb.OleDbConnection
Public Adap As OleDb.OleDbDataAdapter
Public Cmd As OleDb.OleDbCommand
Public Dt As DataSet
Public dr As OleDb.OleDbDataReader = Nothing
Public selectText As String = [Ô][Ô]
Public myCommand As OleDb.OleDbCommand = Nothing
Public ConnectionString As String = [Ô]Provider=Microsoft.Ace.Oledb.12.0; Data Source=[Ô] & Application.StartupPath & [Ô]\BancoDados.accdb;[Ô]
Public strConn As OleDb.OleDbConnection
strConn = New OleDb.OleDbConnection(ConnectionString)
strConn.Open()
selectText =[Ô]SELECT * FROM TABELA[Ô]
myCommand = New OleDb.OleDbCommand(selectText, strConn)
dr = myCommand.ExecuteReader()
While (dr.Read())
MINHAVARIAVEL=(dr([Ô]CAMPO_SQL[Ô]).ToString)
End While
strConn.Close()
Return True
Mto. Obrigado!! Vou fazer o Teste!!
Tópico encerrado , respostas não são mais permitidas