Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display value in text box as per selection of combo box.For that I am using following code.(using direct value Part No=51)
VB
Dim disp As String = " Select Item_desc From Item_Master where Part_no=51"
obj.SetCon()
cmd.CommandText = disp
cmd.Connection = obj.SetCon
rd = cmd.ExecuteReader

If rd.Read = True Then
    txtItemDesc.Text = rd("Item_desc")
End If
con.Close()


using above code I am getting value from database.
but I want dynamically for that I am using following query:
VB
Dim disp As String = (" Select Item_desc From Item_Master where Part_no='" & cmbPartNo.Text & "'")

for this query system give me error: Operator '&' is not defined for string " Select Item_desc From Item_Mast" and type 'DataRowView'.

Thanks in advance
Posted
Updated 9-Jan-13 3:29am
v3
Comments
thomasriley 9-Jan-13 8:41am    
Is your Part_no an INT in your database?
Yogi ,Pune 9-Jan-13 9:31am    
No . Part_No is varchar
Orcun Iyigun 9-Jan-13 8:47am    
IN which code block you are doing this process? I think you need to do it in combobox's selectedindexchanged event
Yogi ,Pune 9-Jan-13 9:30am    
Yes I did it in Com box selectedindexchanged event

If Part_no is an INT in the database then use the following query:
SQL
SELECT Item_desc 
FROM Item_master 
WHERE Part_no = '" + CInt(cmbPartNo.SelectedText) + "'
 
Share this answer
 
Use this instead:
SQL
SELECT Item_desc 
FROM Item_master 
WHERE Part_no = '" + cmbPartNo.SelectedItem.ToString + "'

This should work for you!
 
Share this answer
 
v2
hi,
instead of cmbPartNo.SelectedText give cmbPartNo.Text
 
Share this answer
 
Comments
Yogi ,Pune 10-Jan-13 9:39am    
Thanks for suggestion.

Now I want to show Item Type also with Item description.
As per selection of cmbPartNo combo box Item Type & Item Description should be display in respective text boxes.
My Part_no is varchar so as per your suggestion i update my query:

Dim disp As String = ("Select Item_desc FROM Item_master WHERE Part_no = '" + cmbPartNo.SelectedText + "'")

Now system not showing any error but problem is :
when i debug the string + cmbPartNo.SelectedText + through this statement system not taking any value. so not showing expected result.
 
Share this answer
 
Comments
thomasriley 9-Jan-13 10:10am    
On which event does the query run? When you click a button or on Form_Load?
thomasriley 9-Jan-13 10:14am    
Your query now seems right as the SelectedText option will output as a string. What do you mean by:
"debugging the string + cmbPartNo.SelectedText + through this statement"?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900