Click here to Skip to main content
12,349,363 members (26,585 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
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)
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:
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 9-Jan-13 2:36am
Edited 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If Part_no is an INT in the database then use the following query:
SELECT Item_desc 
FROM Item_master 
WHERE Part_no = '" + CInt(cmbPartNo.SelectedText) + "'
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Use this instead:
SELECT Item_desc 
FROM Item_master 
WHERE Part_no = '" + cmbPartNo.SelectedItem.ToString + "'
This should work for you!
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

hi,
instead of cmbPartNo.SelectedText give cmbPartNo.Text
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100