Multicolumn listbox in smart device application
-
Good morning, I am working on a smart device application. I want to create a listbox with 3 columns which get there data from a local database .sdf I tried the following code but an exception occurred.
private void button1_Click(object sender, EventArgs e)
{
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
SqlCeConnection sqlceconn = new SqlCeConnection(wCS);
SqlCeCommand command = sqlceconn.CreateCommand();
command.CommandText = "SELECT [ID]+\" \"+[Magasin]+\" \"+ [qtyonhand] AS IMQ from stocks where ID like %@txt%";
SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
SqlCeParameter txt = new SqlCeParameter("@txt", SqlDbType.NVarChar);
txt.Value= textBox1.Text;
command.Parameters.Add(txt);
DataSet ds = new DataSet();
adapter.Fill(ds);
listBox1.DataSource = ds.Tables[0];
listBox1.DisplayMember="IMQ";
}this is the exception
there is an error parsing the querry. [token line number =1, token line offset=77, Token in error = %]
thank you in advance.
-
Good morning, I am working on a smart device application. I want to create a listbox with 3 columns which get there data from a local database .sdf I tried the following code but an exception occurred.
private void button1_Click(object sender, EventArgs e)
{
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
SqlCeConnection sqlceconn = new SqlCeConnection(wCS);
SqlCeCommand command = sqlceconn.CreateCommand();
command.CommandText = "SELECT [ID]+\" \"+[Magasin]+\" \"+ [qtyonhand] AS IMQ from stocks where ID like %@txt%";
SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
SqlCeParameter txt = new SqlCeParameter("@txt", SqlDbType.NVarChar);
txt.Value= textBox1.Text;
command.Parameters.Add(txt);
DataSet ds = new DataSet();
adapter.Fill(ds);
listBox1.DataSource = ds.Tables[0];
listBox1.DisplayMember="IMQ";
}this is the exception
there is an error parsing the querry. [token line number =1, token line offset=77, Token in error = %]
thank you in advance.
Of course there's an error...your select command is not written correctly. This is what it looks like to SQL:
SELECT [ID]+" "+[Magasin]+" "+ [qtyonhand] AS IMQ from stocks where ID like %@txt%
You need to look at a SQL reference and see how to write a proper SQL Select statement. Why did you put in
+\" \"
? Where in the world did you see that. And please, start using proper naming conventions. When you add a control, change it's name to reflect what it is and what it holds. Take a look here: Naming convention[^]