-
May 12th, 2020, 11:58 AM
#1
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
-
May 12th, 2020, 01:06 PM
#2
Re: Filling combobox and radiobutton with sql information
[Thread moved from C++ forum as VB code. When posting code, please use code tags so that the code is readable. Go Advanced, select the formatted code and click '#'].
Cheers!
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
May 12th, 2020, 01:27 PM
#3
Re: Filling combobox and radiobutton with sql information
Originally Posted by Goncalof7
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!
...
Can u help me with this problem?
Regards!
Does your code compile?
If there was no problem with compiling then did you try do debug it to be sure you get the correct data from SQL database?
Victor Nijegorodov
-
May 12th, 2020, 11:45 PM
#4
Re: Filling combobox and radiobutton with sql information
Your commented line of code tries to select an item in a combo box but you say you are trying to fill it. You have to add the items to the combo before you can select one.
Always use [code][/code] tags when posting code.
-
May 14th, 2020, 04:16 AM
#5
Re: Filling combobox and radiobutton with sql information
Hi VictorN,
Yes i can compile and debug without no problem, but when i try to fill the datagridview only textbox's get the information.
Combobox doesn't change!
Regards.
-
May 14th, 2020, 04:17 AM
#6
Re: Filling combobox and radiobutton with sql information
DataMister,
Can you explain better please ou give a example?
Regards.
-
May 19th, 2020, 06:34 PM
#7
Re: Filling combobox and radiobutton with sql information
You only show one line of code that references a combobox. That line is commented out, It tries to select an item in the combo box. If there is nothing in the combo it will give an error. You code does not add any items to the combo box.
If you want to add that item(6) to the combo box then rather than using selected item you need to use items.add
Always use [code][/code] tags when posting code.
-
September 24th, 2020, 07:57 AM
#8
Re: Filling combobox and radiobutton with sql information
Hello!
Check out a mysql database tool for relational databases that provide support for MySQL, MariaDB, and some other popular relational databases.
Last edited by W231; September 28th, 2020 at 07:44 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|