Wildcard Query using C# and Access
-
Hi, I'm attempting to perform a wild card query using C# and microsoft access. The results will be placed in a data grid. Ive tried using "*" ,"#" and "?" symbols but it still wont work heres my query statement.. daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '*{0}*'", search), conn); daGuests is my data adapter search is a string taken from a textbox.. is there something wrong with my code? im pretty sure theres nothing wrong with my other codes, the daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '{0}'", search), conn); statement works perfectly. Hope you guys can help.
-
Hi, I'm attempting to perform a wild card query using C# and microsoft access. The results will be placed in a data grid. Ive tried using "*" ,"#" and "?" symbols but it still wont work heres my query statement.. daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '*{0}*'", search), conn); daGuests is my data adapter search is a string taken from a textbox.. is there something wrong with my code? im pretty sure theres nothing wrong with my other codes, the daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '{0}'", search), conn); statement works perfectly. Hope you guys can help.
I don't use Access anymore but the SQL should be closer to:
"SELECT * FROM Assignee WHERE SN LIKE '%{0}%'"
I'm not real sure about the % characters. They might be something else.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Hi, I'm attempting to perform a wild card query using C# and microsoft access. The results will be placed in a data grid. Ive tried using "*" ,"#" and "?" symbols but it still wont work heres my query statement.. daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '*{0}*'", search), conn); daGuests is my data adapter search is a string taken from a textbox.. is there something wrong with my code? im pretty sure theres nothing wrong with my other codes, the daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '{0}'", search), conn); statement works perfectly. Hope you guys can help.
I consider that we could use 2 character '*' and '%' based on what I need In SQL query, we use "Select * frm Assignee WHERE SN like 'Th%'" In Crystal Report, we use CrystalReport1.DataDefinition.RecordSelectionFomular = "{Assignee.SN} like 'Th*'";
It seem to be a solution or an answer.
-
Hi, I'm attempting to perform a wild card query using C# and microsoft access. The results will be placed in a data grid. Ive tried using "*" ,"#" and "?" symbols but it still wont work heres my query statement.. daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '*{0}*'", search), conn); daGuests is my data adapter search is a string taken from a textbox.. is there something wrong with my code? im pretty sure theres nothing wrong with my other codes, the daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN = '{0}'", search), conn); statement works perfectly. Hope you guys can help.
Hi, On microsoft access, we have 2 wild characters, "*" and "?". So the mistake is in using "=" instead of the LIKE. Try to use sentance as: daGuests = new OleDbDataAdapter(string.Format("SELECT * FROM Assignee WHERE SN LIKE '*{0}*'", search), conn); and I hope it will work for you. Manoj