Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Multicolumn listbox in smart device application

Multicolumn listbox in smart device application

Scheduled Pinned Locked Moved C#
databasejsonhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bacem smari
    wrote on last edited by
    #1

    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.

    W 1 Reply Last reply
    0
    • B bacem smari

      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.

      W Offline
      W Offline
      William Winner
      wrote on last edited by
      #2

      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[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups