CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Mar 2020
    Posts
    6

    Exclamation Filling combobox and radiobutton with sql information

    Hi,

    I'm tryinng to fill a combobox and radiobutton with the info that i have insert in my sql database.
    I what to display the name of "Agente" in the combobox when i click in the "id" that will fill all textbox's, combobox!
    This is the code i'm trying:

    Code:
    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
            Try
                con.Open()
                i = Convert.ToInt32(DataGridView1.SelectedCells.Item(0).Value.ToString())
                cmd = con.CreateCommand()
                cmd.CommandType = CommandType.Text
                cmd.CommandText = "Select Agentes.[Id], Agentes.[Nome],Agentes.[Email],Agentes.[Localidade], Lojas.[Nome] as Loja, Agentes.[Anotacoes]
                                    From [TesteAna].[dbo].[Agentes]
                                    Inner join [TesteAna].[dbo].[Lojas] on Lojas.Id= Agentes.Loja 
                                    where Agentes.[Id]=" & i & ""
                cmd.ExecuteNonQuery()
                Dim dt As New DataTable()
                Dim da As New SqlDataAdapter(cmd)
                da.Fill(dt)
                Dim dr As SqlDataReader
                dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
                While dr.Read
                    TextBox1.Text = dr.GetString(1)
                    TextBox2.Text = dr.GetString(2)
                    TextBox3.Text = dr.GetString(3)
                    TextBox4.Text = dr.GetString(4)
                    TextBox5.Text = dr.GetString(5)
                    'ComboBox1.SelectedItem = dr.GetString(6) -- 'were is where i'm trying to fill combobox!
                End While
            Catch ex As Exception
                'MsgBox(ex.Message)
            End Try
        End Sub
    Can u help me with this problem?
    Regards!
    Last edited by 2kaud; May 12th, 2020 at 01:05 PM. Reason: Added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured