Jump to content
Jhosepy

Combobox com dados do banco

Recommended Posts

Jhosepy

Estou há alguma horas procurando uma resposta para meu problema mas não acho nada. Me ajudem a achar onde está errado, não acusa erro de compilação mas também não aparece os dados.

Aqui está o código:

Private Sub comboti_SelectedIndexChanged(sender As Object, e As EventArgs) Handles comboti.SelectedIndexChanged

        Dim conexao As String
        conexao = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\jhose\source\repos\estoque\Estoque\dataestoque.mdf;Integrated Security=True"

        Dim cn As New SqlConnection(conexao)
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If
        Dim cm As New SqlCommand
        'gravando dados do formulário clientes
        cm.Connection = cn

        Dim sqlDados As String = "SELECT * FROM tipo"

        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim dt As DataTable = New DataTable
        da.Fill(dt)

        comboti.ValueMember = "Id_Tipo"
        comboti.DisplayMember = "Nome_Tipo"
        comboti.DataSource = dt

        'FECHA A CONEXÃO COM O BANCO DE DADOS
        cn.Close()
        Try
        Catch ex As Exception
            'EM CASO DE ERRO, RETORNA A MENSAGEM
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "SELECT_Nome_Tipo")

        'FECHA A CONEXÃO COM O BANCO DE DADOS
        cn.Close()
        End Try
    End Sub
End Class

Share this post


Link to post
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.