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. Creating a checklist using checkbox tool in csharp smart device project

Creating a checklist using checkbox tool in csharp smart device project

Scheduled Pinned Locked Moved C#
databasecsharp
5 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.
  • T Offline
    T Offline
    Tunisien86
    wrote on last edited by
    #1

    Hello, I am developing a GMAO csharp smart device application.I am in the step of creating a checklist using checkbox tool added dynamically:

    I have two tables:Travaux (Works in English) and Actions related by the two fields Nature (table Travaux)and typeTravail(Table Actions).If the user enters the number of the work(NBT the pk_Travaux),the system adds a number of checkboxs equal to the steps that should the user follows to accomplish(field step in Actions table).After that,the user has the possibility to check or not the step if he did it.All the traitments will be done dynamically with the database

    My select statement is:

    select Etape from Action where ((Travaux.NBT=textbox1.text) and (Travaux.Nature=Action.TypeTravail))

    Equal of what this select returns,it will add dynamically checkboxs I tried with this code but not working due to some errors :((

    private void button1_Click(object sender, EventArgs e)
    {
    //Create the connection
    string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
    SqlCeConnection sqlceconn = new SqlCeConnection(wCS);

            //Create the command
            SqlCeCommand command = sqlceconn.CreateCommand();
            command.CommandText = "Select NBT, Nature from Travaux where NBT=@NBT ";
    
            //Add the parameters
            string s1 = textBox1.Text; //store the login name here YOU MUST FILL THIS IN
            SqlCeParameter NBT = new SqlCeParameter("@NBT", SqlDbType.NVarChar);
            NBT.Value = s1;
    
            command.Parameters.Add(NBT);
            //Create the adapter
            SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
    
            //Create and fill the dataset
            DataSet ds = new DataSet();
    
            try
            {
                adapter.Fill(ds, "SQL Temp Table");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            foreach (DataRow da in adapter)
            { string s = adapter\["Nature"\]; }
    
            if ((ds.Tables.Count > 0) && (ds.Tables\["SQL Temp Table"\] != null))
            {
                MessageBox.Show("Number of row(s) - " + ds.Tables\["SQL Temp Table"\].Rows.Count);
                if (ds.Tables\["SQL Temp Table"\].Rows.Count > 0)
                {
                    MessageBox.Show("Numéro de BT trouvé");
                    SqlCeCommand command1 = sqlceconn.CreateCommand();
    
    T 1 Reply Last reply
    0
    • T Tunisien86

      Hello, I am developing a GMAO csharp smart device application.I am in the step of creating a checklist using checkbox tool added dynamically:

      I have two tables:Travaux (Works in English) and Actions related by the two fields Nature (table Travaux)and typeTravail(Table Actions).If the user enters the number of the work(NBT the pk_Travaux),the system adds a number of checkboxs equal to the steps that should the user follows to accomplish(field step in Actions table).After that,the user has the possibility to check or not the step if he did it.All the traitments will be done dynamically with the database

      My select statement is:

      select Etape from Action where ((Travaux.NBT=textbox1.text) and (Travaux.Nature=Action.TypeTravail))

      Equal of what this select returns,it will add dynamically checkboxs I tried with this code but not working due to some errors :((

      private void button1_Click(object sender, EventArgs e)
      {
      //Create the connection
      string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
      SqlCeConnection sqlceconn = new SqlCeConnection(wCS);

              //Create the command
              SqlCeCommand command = sqlceconn.CreateCommand();
              command.CommandText = "Select NBT, Nature from Travaux where NBT=@NBT ";
      
              //Add the parameters
              string s1 = textBox1.Text; //store the login name here YOU MUST FILL THIS IN
              SqlCeParameter NBT = new SqlCeParameter("@NBT", SqlDbType.NVarChar);
              NBT.Value = s1;
      
              command.Parameters.Add(NBT);
              //Create the adapter
              SqlCeDataAdapter adapter = new SqlCeDataAdapter(command);
      
              //Create and fill the dataset
              DataSet ds = new DataSet();
      
              try
              {
                  adapter.Fill(ds, "SQL Temp Table");
              }
              catch (Exception ex)
              {
                  MessageBox.Show(ex.Message);
              }
              foreach (DataRow da in adapter)
              { string s = adapter\["Nature"\]; }
      
              if ((ds.Tables.Count > 0) && (ds.Tables\["SQL Temp Table"\] != null))
              {
                  MessageBox.Show("Number of row(s) - " + ds.Tables\["SQL Temp Table"\].Rows.Count);
                  if (ds.Tables\["SQL Temp Table"\].Rows.Count > 0)
                  {
                      MessageBox.Show("Numéro de BT trouvé");
                      SqlCeCommand command1 = sqlceconn.CreateCommand();
      
      T Offline
      T Offline
      Tarakeshwar Reddy
      wrote on last edited by
      #2

      Tunisien86 wrote:

      foreach (DataRow da in adapter) { string s = adapter["Nature"]; }

      Should be

      foreach (DataRow da in ds.Tables[0].Rows)
      {
      string s = da["Nature"];
      }

      Tunisien86 wrote:

      foreach (DataRow ligne in adapt.) { System.Console.WriteLine(adapt[0]); }

      This should be

      foreach (DataRow dataRow in dat.Tables[0].Rows)
      {
      System.Console.WriteLine(dataRow[0]);
      }

      T 1 Reply Last reply
      0
      • T Tarakeshwar Reddy

        Tunisien86 wrote:

        foreach (DataRow da in adapter) { string s = adapter["Nature"]; }

        Should be

        foreach (DataRow da in ds.Tables[0].Rows)
        {
        string s = da["Nature"];
        }

        Tunisien86 wrote:

        foreach (DataRow ligne in adapt.) { System.Console.WriteLine(adapt[0]); }

        This should be

        foreach (DataRow dataRow in dat.Tables[0].Rows)
        {
        System.Console.WriteLine(dataRow[0]);
        }

        T Offline
        T Offline
        Tunisien86
        wrote on last edited by
        #3

        Hi, Thanks Reddy,the errors disappears all with some corrections:

        foreach (DataRow da in ds.Tables[0].Rows)
        {
        string s = da[0].ToString();}

        .I want now to add every row it found after executing the select request:

        command1.CommandText = "Select NoEtape, Etape from Action where TypeTravail=@typ ";

        I create a listview and I wanna add like items every result of the select.I modify my code in his end like this:

        ............
        foreach (DataRow dataRow in dat.Tables[0].Rows)
        {
        ListViewItem item = new ListViewItem();
        item.Text = dataRow[0].ToString();
        listView1.Items.Add(item);
        System.Console.WriteLine(dataRow[0]);
        }

                    }
                    else MessageBox.Show("Veuillez saisir un autre NBT");
                }
                adapter.Dispose();
                sqlceconn.Dispose();
                command.Dispose();
        
            }
        
        
        }
        

        But this modification doesn't show any thing in the listviewitem. Thanks a lot for u suggestions :((

        T 1 Reply Last reply
        0
        • T Tunisien86

          Hi, Thanks Reddy,the errors disappears all with some corrections:

          foreach (DataRow da in ds.Tables[0].Rows)
          {
          string s = da[0].ToString();}

          .I want now to add every row it found after executing the select request:

          command1.CommandText = "Select NoEtape, Etape from Action where TypeTravail=@typ ";

          I create a listview and I wanna add like items every result of the select.I modify my code in his end like this:

          ............
          foreach (DataRow dataRow in dat.Tables[0].Rows)
          {
          ListViewItem item = new ListViewItem();
          item.Text = dataRow[0].ToString();
          listView1.Items.Add(item);
          System.Console.WriteLine(dataRow[0]);
          }

                      }
                      else MessageBox.Show("Veuillez saisir un autre NBT");
                  }
                  adapter.Dispose();
                  sqlceconn.Dispose();
                  command.Dispose();
          
              }
          
          
          }
          

          But this modification doesn't show any thing in the listviewitem. Thanks a lot for u suggestions :((

          T Offline
          T Offline
          Tarakeshwar Reddy
          wrote on last edited by
          #4

          Tunisien86 wrote:

          dat.Tables[0].Rows

          Did you check if the DataTable has any rows after executing the select statement? Does it even get into the foreach loop?

          T 1 Reply Last reply
          0
          • T Tarakeshwar Reddy

            Tunisien86 wrote:

            dat.Tables[0].Rows

            Did you check if the DataTable has any rows after executing the select statement? Does it even get into the foreach loop?

            T Offline
            T Offline
            Tunisien86
            wrote on last edited by
            #5

            Hi, Thank u for u help.I found the solution using the listview tool(with its option checked) and all gets well.This is the link after that solved my issue: http://msdn.microsoft.com/en-us/library/ms229643.aspx[^] Thanks a lot and can u have a look to my new thread:DataGridView-DataBase in csharp smart device posted a few minutes ago Thanks :)

            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