In order to search by name, the text in the txtName must mach some entry in the DVD table in SQL.
If you defined the Name field in the SQL to be char or nchar, the legth is significant, because the content is filled with blancs in the db, so comparing without blancs can fail.
If you defined the field Name to be a BLOB (text, image, etc), is not serchable
If you defined the field to be char, varchar, nchar or nvarchar, the compare occurs as defined in the comparation method of the db: Binary, dictionary, case sensitive or not, etc, and for the nchar and nvarchar the compare is based on unicode while for the others is based on ascii. Also the base language for the SQL table plays in this scenario.
On the other question, you can add an option group with both possibilities: Search by ID, Serach by Name. Then, when constructing the select you can adjust the where clause accorging to the selection made asking if the option is checked.
Hope this helps
lolafuertes
Practically a Posting Shark
889 posts since Oct 2008
Reputation Points: 164
Solved Threads: 189
Skill Endorsements: 5
WHERE Clause is the condition of what the inquiry will be based on.
If you do:
"SELECT * FROM MyTable" - it will return all data from database table (data are meant all rows, since we use * simbol)
If you do:
"SELECT * FROM MyTable WHERE Name = "John"; - it will return ONLY rows where in the Name column is John (same as your example).
This means the whole name "John" not only "Jon", or "J".
Maybe you entered only "J" or "Joh" and thats why you didnt get any results.
Thats why sql querying supporty partial values (or starting from beginning, or in form somewhere in the middle, or to the end).
Thats why we must use LIKE keyword and % simbol.
If you do:
... WHERE Name = 'J%' - will return all rows that STARTS with J
... WHERE Name = '&n' - will return all rows that ENDS with n
... WHERE NAme = '&hn&' - will return all rows that CONTAINS hn in some where in the middle!
I hope I was clear enough about using LIKE keyword in sql queries.
So I your case I assume you wanna get all rows that starts with some name, so you do:
"SELECT * From DVD where Name LIKE ='" + txtName.Text + "%'";
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Question Answered as of 11 Months Ago by
nmaillet,
lolafuertes
and
Mitja Bonca