Jump to content

selecionar um dado na base dados e colocar numa variavel


Recommended Posts

Tens aqui um bom exemplo, só precisas de migrar para c#. Tenta, se surgirem dificuldades posta cá que eu logo dou-te auxilio.

Dim query As String = "QUERY"
Dim cmd As New SqlCommand(query, conexao)
' Cria uma consulta paremetrizada
  cmd.Parameters.Add(New SqlParameter("Nome", nome))
' executa a consulta.
  Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleRow)
' exibe o resutlado nas labels
	    If dr.HasRows Then
	    label1.text= dr.Item(1).ToString
   label2.text= dr.Item(0).ToString
  End if

Estranha forma de vida que tem a capacidade de transformar comandos em mensagens de erro.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.