Jump to content

combobox value member


gastao

Recommended Posts

Boa tarde, tou aqui com a seguinte situação tenho uma base de dados com tabelas relacionadas, e quero gravar na tabelaA um campo da tabelaB em que as tabelas estao relacionadas por um campo.

a minha questao e a seguinte mostrar os campos numa combobox vindas da tabelaB e gravar na tabelaA esse campo relacionado, eu ate consigo listar na combo so que depois nao csg gravar estou com o seguinte codigo:

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If con.State = ConnectionState.Open Then con.Close()
            con.Open()
            Call dados() 'procedimento que me chama a listagem de dados q tenho para o form
            Dim ds As New DataSet
            Dim dt As New DataTable
            Dim adap As New OleDbDataAdapter("select * from tabela2", con)
            adap.Fill(ds, "tabela2")
            dt = ds.Tables(0)
    With Me.ComboBox2
                .DataSource = ds.Tables(0).DefaultView
                .DisplayMember = "nome"
                .ValueMember = "idtabela2"
                'Call Limpa()
            End With
                con.Close()
    End Sub

codigo do botao de gravar:

If con.State = ConnectionState.Open Then con.Close()
                    Dim st As String
                    st = "INSERT INTO Tabela(nome,idade,idtabela2)VALUES('" & TextBox2.Text & "','" & TextBox3.Text & "','" & ComboBox2.valuemember & "')"
                    Dim cmd As New OleDbCommand(st, con)
                    con.Open()
                    cmd.ExecuteNonQuery()
                    MsgBox("Gravado")
Link to comment
Share on other sites

con.Open()
            Dim cmd As New OleDbCommand("select * from familia where nome = '" & ComboBox4.Text & "'", con)
            Dim drdr As OleDbDataReader
            drdr = cmd.ExecuteReader
            drdr.Read()
            TextBox1.Text = drdr.Item("idfamilia1")
            TextBox5.Text = drdr.Item("nome")
            ComboBox2.Text = drdr.Item("idfamilia2")


            Dim cmd2 As New OleDbCommand("select * from familia2 where idfamilia2= '" & ComboBox2.Text & "'", con)
            Dim drdr2 As OleDbDataReader
            drdr2 = cmd2.ExecuteReader
            drdr2.Read()
            TextBox7.Text = drdr.Item("nome2")


            con.Close()

eu aqui ao tentar listar o campo relacionado vindo da minha tabela 2 da me um 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.