dear friends,
I develop an Win application by using MS Access.I have got a problem in SQL statement.I have got a form that has got 2 ComboBox and a DataGridView.The name of the first is cmbCategories and the second one is cmbContent.Content is listing the content of categories.I use an array to transfer letters when I choose the category in cmbCategories as it is Alphabetical Array.When I choose a letter from cmbContent like A,B or another one,but no records is listing in the DataGridView.I try to use "Like" statement for this action.It is like this:
string strSQL = "select FilmName from films where FilmName like" + "'" + cmbContent.Text + "*'";
cmbContent has got the Alphabetical letters by sequence.I want to list the FilmName that is beginning as alphabetic.For example,when I choose letter A,the films begins A must be listed.Does anybody help me?Thanks for your help.
AlanPosted Sep 10, 2007, 6:56 AM
To be honest, I can't see anything else wrong with it :-/
Although I'm not suggesting this as a solution, does it work if you hard-code the LIKE clause:
string strSQL = "select FilmName from films where FilmName like 'A*'";
If it does, then there may be a problem with cmbContent.Text - perhaps some trailing spaces or something like that. You could use cmbContent.Text.TrimEnd() to check for that.
keremPosted Sep 10, 2007, 5:58 AM
private DataView Get_DataAlphabetic()
{
string constr = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" + Environment.CurrentDirectory + "\\mdb\\film_db.mdb";
OleDbConnection con_ole = new OleDbConnection(constr);
string strSQL = "select FilmName from films where FilmName like " + "'" + cmbContent.Text + "*'";
OleDbDataAdapter da = new OleDbDataAdapter(strSQL, con_ole);
DataTable dt = new DataTable();
da.Fill(dt);
DataView dv = new DataView(dt);
dv.Sort = "FilmName ASC";
da.Dispose();
con_ole.Close();
return dv;
}
I send it to a datagrid's datasource property in another method as I use cmobobox's SelectedIndexChanged method.Hope it is clear.I wait for your replies
AlanPosted Sep 9, 2007, 5:21 PM
Try inserting a space after 'like':