Hi friends. I'm newest user for Visual Studio 2005 VB, i couldn't find right way, I need some information. Sorry My English is not so good. I can explain so; I have one combobox, i connected that to my db(Access) There is so much Column, When i select somthing in Combobox i wish textbox show what a that row compoist for other column.
-----------------------------------------------------------------------
| Sno | asd | 312sad | kashs| sakd | sadas| yuha | > Column name
-----------------------------------------------------------------------
| 1 | asdasd | 13 | 11 | 13 | 12 | 12,5 | > values
-----------------------------------------------------------------------
| 2 | Kilyun | 5 | 5,2 | 4,8 | 4,5 | 5 | > values
-----------------------------------------------------------------------
I have Table Like this.
When i select asdasd in combobox i wish textbox1 show 13 (upper Value) and Label1 show column name (312sad) i couldn't solve this problem. I searh so many times in so many places. Can you help me about it
Note : I show this table other from in myproject with datagirdwiev.

About Combobox
VSU
My DB is called PhilDataSet
I want to use a text value(I can use the index value if necessary) selected from a combobox(working) in a form as the WHERE part of an SQL statement that returns the columns "Cards" and "Hand_Group" from my PhilDataSet DB into text boxes with the intention later of manipulating some of that data to pull other stuff from a second DB.
Where I'm running into trouble is getting just my WHERE data to come out of the DB. I can get the whole DB table to show in my form, but not the specific data when I add the WHERE argument to the SELECT and FROM statements. I'm doing a lot of data "echoing" to verify I'm getting the values out that I'm intending to. Here's some of the code with the error I'm currently getting listed just below the line where it occurs, in Red:
Dim strCardSql As String = "SELECT all FROM Dealt_Cards WHERE Cards = " & comboMyHand.SelectedItem & "'"
Dim cmdCards As New OleDb.OleDbCommand(strCardSql, cardConn)
Dim readerCards As OleDb.OleDbDataReader()
'THE ERROR I Get from the line above is: "The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect."
If readerCards.Read() Then
Label4.Text = readerCards("Cards")
'returns the WHERE value in the Cards column to my form
Label5.Text = readerCards("Group")
'returns the WHERE value from the Group column to my form
End If
readerCards.Close()
I think if I can figure out what goes in the ()'s I'll be ok, but after a day of reading online, I've not figured it out yet. I've tried a few combos so far to no avail, getting a few other errors.
Thanks for any help,
Jet
Sarah Roberts
hi,
you are welcome paul, from the number of your posts i see you as expert here in this forum and i have aquestion for you,
first time i came here i saw icon about if this posting contain a code(vb/c#) now i don't see it anymore to mark the code in my posting so don't you know how i can get this back
thx
Jason Smith - MSFT
If you wanna change to the next cell, then you'll have to change the value member text to the field that you want to show.
combobox1.DataSource = myDataSet
combobox1.DisplayMember = "asd"
combobox1.ValueMember = "sakd"
And on your combobox selectedindex changed do this:
TextBox1.Text = combobox1.SelectedValue
Label1.Text = combobox1.ValueMember
cheers,
Paul June A. Domag
Dazzl
Yep the value member could only be used once. You'll have to create some codes to enable that. Here's an example:
SqlCommand cmd = new SqlCommand("SELECT * FROM Table1 WHERE asd = '" + comboBox1.Text + "'", con);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read()) {
label1.Text = reader["field1"].ToString();
label2.Text = reader["field2"].ToString();
}
reader.Close();
cheers,
Paul June A. Domag
wendallsan
dano992
You can do that this way. Upon binding your combobox to your datatable or dataset:
combobox1.DataSource = myDataSet
combobox1.DisplayMember = "asd"
combobox1.ValueMember = "312sad"
And on your combobox selectedindex changed do this:
TextBox1.Text = combobox1.SelectedValue
Label1.Text = combobox1.ValueMember
cheers,
Paul June A. Domag
Adrian Russell
hi,
i'm still learning like you and i'm not sure from this but try this out
combobox1.DataSource = myDataSet
combobox1.DisplayMember = "asd"
combobox1.ValueMember = "312asd" &"|"& "sakd"
and in your compobox selectedindex add this code
Dim Keys() as string
keys = spilit(combobox1.valuememeber, "|")
textbox1.tet = combobox1.selecteditem
label1.text = keys(0) + vbnewline
label1.text &= keys(1)
Mazdisna Meenavee Mehr
Sorry i couldn't understand rigth. I have one combobox, label and textbox. And my database in access. there is 28 Columns and 400 rows. Can you write example code for me.
SqlCommand cmd = new SqlCommand("SELECT * FROM Table1 WHERE asd = '" + comboBox1.Text + "'", con); ' i connected combobox to my db
SqlDataReader reader = cmd.ExecuteReader(); ' search what i select in combo
if (reader.Read()) {
label1.Text = reader["field1"].ToString(); ' this is selected item value
label2.Text = reader["field2"].ToString(); ' thsi is column of selected item value
}
reader.Close();
did i understand right
danieldp
hi,
he wrote the code in the c fashon anyway in visual basic you have to define somethings if you use the wizards
double click your combobox in your form and when you go to codeview put this code
dim con as new sqlconnection("put the text of your connection here")
dim sqlstring as string = "select all from MytableName where asad = "& combobox1.selecteditem & "'"
dim cmd as new sqlcommand(sqlstring, conn)
dim reader as sqldatareader = cmd.executereader()
while reader.read()
label1.text = reader("OneOfYourColumenNameThatYouWant")
label2.text=reader("YourOtherColumnNameThatYouWant")
end while
close.reader()
SpliCEd
thx Mr. Paul
El Bruno
k.m
Thanks shakalama for converting my code. I kinda forgot that this is a VB forum. Here's a convertion of the code:
dim con as new sqlconnection("put the text of your connection here")
dim sqlstring as string = "select all from MytableName where asad = "& combobox1.selecteditem & "'"
dim cmd as new sqlcommand(sqlstring, conn)
dim reader as sqldatareader = cmd.executereader()
if reader.read() then
label1.text = reader("OneOfYourColumenNameThatYouWant")
label2.text=reader("YourOtherColumnNameThatYouWant")
end if
close.reader()
you can just modify the code to satisfy your needs...
cheers,
Paul June A. Domag
gulatis
tballx
Hi,
The previous texteditor which contains the C#/VB code button has already been replaced by the texteditor that you now use in the forum. Although it doesn't support the VB/C# code blocks, the new editor greatly supports the cut and paste from the VS IDE.
Here;s the thread that discusses it. http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=80569&SiteID=1
cheers,
Paul June A. Domag