Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
i have two table and find record with like operator and record show in grid view
datagridview show a part table record but his coulumn name modalID, but i have type a textbox modalname this mathod solution

part table
brand modalId partId partname qty mrp


modal table
modalId brandId modalname


What I have tried:

SQL
select modalname from modal1 where modalId =(select modalId from partstock where modalname='')
Posted
Updated 25-Jun-18 20:07pm
v2
Comments
Member 13886465 25-Jun-18 13:43pm    
please give me answer fast
Bryian Tan 25-Jun-18 15:28pm    
Is modalname field in both table?

You need a join between your two tables, in this case probably an inner join...like this:
from modal inner join part on modal.modalid = part.modalid

The where can just reference the modalname then without a subquery.

Also, to use a subquery as in your example replace '=' with 'in'.
 
Share this answer
 
Comments
Maciej Los 26-Jun-18 2:06am    
5ed!
Member 13886465 29-Jun-18 0:03am    
str = "Select * from part_stock where modalid=(select modalid from modal1 where modalname like '" & TextBox1.Text & "%') and part_name like '" & TextBox2.Text & "%' and qty like'" & TextBox3.Text & "%' and mrp like'" & TextBox4.Text & "%'"

this is perfect query but one error
i am type the textbox single single letter and error is one record can be return this sub query
Member 13886465 29-Jun-18 0:04am    
but error is only sub query
You need to learn
* SQL Joins[^]; in this case you will work with inner join
* SQL LIKE Operator[^]

You are talking about SQL query, you have tagged as SmartWatch. Wrong tagging.
You should also mention what database you are using.
 
Share this answer
 
Comments
Maciej Los 26-Jun-18 2:06am    
5ed!

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