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. what can I do to my poorful combobox to be filled????

what can I do to my poorful combobox to be filled????

Scheduled Pinned Locked Moved C#
databasequestioncsharpcomsysadmin
9 Posts 5 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

    Hi guys, I develop a csharp smart device.I want know now fill my combobox with data extractedfrom my database .mdf(wishing that the TCP/IP goes well and the connection to my local server works well :laugh: ). My code is:

    string sConnection = "Provider=SQLNCLI.1;Persist Security Info=False;User ID=sa;Initial Catalog=GMAO;Data Source=127.0.0.1,1433;Password=sa;";
    string sSQL = "SELECT com FROM energie; ";
    SqlConnection conn = new SqlConnection(sConnection);
    SqlCommand comm = new SqlCommand(sSQL, conn);
    DataSet ds = new DataSet();

            SqlDataAdapter da = new SqlDataAdapter(sSQL,conn);   
            SqlDataReader dr = null;
            try
            {
                comm.Connection.Open();
                da.Fill(ds, "SQL Temp Table");
                foreach (DataRow d in ds.Tables\[0\].Rows)
                {
                    MessageBox.Show("xxxx");
                    comboBox1.Items.Add(d.ItemArray\[0\].ToString());
                }  
    
            }
            catch (SqlException ex)
            {
                MessageBox.Show("connexion impossible");
                MessageBox.Show(ex.Message);
                return;
            }
    
            dr.Close();
            comm.Connection.Close();
    

    Still not filled after running :( . what is the problem??? Thanks

    realJSOPR L 2 Replies Last reply
    0
    • T Tunisien86

      Hi guys, I develop a csharp smart device.I want know now fill my combobox with data extractedfrom my database .mdf(wishing that the TCP/IP goes well and the connection to my local server works well :laugh: ). My code is:

      string sConnection = "Provider=SQLNCLI.1;Persist Security Info=False;User ID=sa;Initial Catalog=GMAO;Data Source=127.0.0.1,1433;Password=sa;";
      string sSQL = "SELECT com FROM energie; ";
      SqlConnection conn = new SqlConnection(sConnection);
      SqlCommand comm = new SqlCommand(sSQL, conn);
      DataSet ds = new DataSet();

              SqlDataAdapter da = new SqlDataAdapter(sSQL,conn);   
              SqlDataReader dr = null;
              try
              {
                  comm.Connection.Open();
                  da.Fill(ds, "SQL Temp Table");
                  foreach (DataRow d in ds.Tables\[0\].Rows)
                  {
                      MessageBox.Show("xxxx");
                      comboBox1.Items.Add(d.ItemArray\[0\].ToString());
                  }  
      
              }
              catch (SqlException ex)
              {
                  MessageBox.Show("connexion impossible");
                  MessageBox.Show(ex.Message);
                  return;
              }
      
              dr.Close();
              comm.Connection.Close();
      

      Still not filled after running :( . what is the problem??? Thanks

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      I suggest you run it under the debugger and see if a) there's a table in the dataset, and b) if there are rows in the table.

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      T 1 Reply Last reply
      0
      • realJSOPR realJSOP

        I suggest you run it under the debugger and see if a) there's a table in the dataset, and b) if there are rows in the table.

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

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

        Hi, I really don't know to run it under the debugger???< Thanks

        P realJSOPR 2 Replies Last reply
        0
        • T Tunisien86

          Hi, I really don't know to run it under the debugger???< Thanks

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          Put a breakpoint in the code at the point you want to break it. There's a shortcut to do this: press F9. Ensure you've built the code as a Debug build and press F5 to run it in debug mode. When your code hits the breakpoint, you can step over code using F10. To step into a function, press F11. To inspect the value of a variable, you can use the locals window, or the quick watch, you can inspect it with the immediate window or you can hover over the input in the running code and see the values in the visualizer. It's that easy, and you really need to learn how to debug your code - it's a vital skill.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          1 Reply Last reply
          0
          • T Tunisien86

            Hi, I really don't know to run it under the debugger???< Thanks

            realJSOPR Offline
            realJSOPR Offline
            realJSOP
            wrote on last edited by
            #5

            It's almost impossible to help you until you learn how to use Visual Studio.

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

            T 1 Reply Last reply
            0
            • T Tunisien86

              Hi guys, I develop a csharp smart device.I want know now fill my combobox with data extractedfrom my database .mdf(wishing that the TCP/IP goes well and the connection to my local server works well :laugh: ). My code is:

              string sConnection = "Provider=SQLNCLI.1;Persist Security Info=False;User ID=sa;Initial Catalog=GMAO;Data Source=127.0.0.1,1433;Password=sa;";
              string sSQL = "SELECT com FROM energie; ";
              SqlConnection conn = new SqlConnection(sConnection);
              SqlCommand comm = new SqlCommand(sSQL, conn);
              DataSet ds = new DataSet();

                      SqlDataAdapter da = new SqlDataAdapter(sSQL,conn);   
                      SqlDataReader dr = null;
                      try
                      {
                          comm.Connection.Open();
                          da.Fill(ds, "SQL Temp Table");
                          foreach (DataRow d in ds.Tables\[0\].Rows)
                          {
                              MessageBox.Show("xxxx");
                              comboBox1.Items.Add(d.ItemArray\[0\].ToString());
                          }  
              
                      }
                      catch (SqlException ex)
                      {
                          MessageBox.Show("connexion impossible");
                          MessageBox.Show(ex.Message);
                          return;
                      }
              
                      dr.Close();
                      comm.Connection.Close();
              

              Still not filled after running :( . what is the problem??? Thanks

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              I suggest you read and study this article[^], even if you are using a different version of Visual Studio. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read formatted code with indentation, so please use PRE tags for code snippets.


              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


              T 1 Reply Last reply
              0
              • realJSOPR realJSOP

                It's almost impossible to help you until you learn how to use Visual Studio.

                .45 ACP - because shooting twice is just silly
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

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

                Hi, It is not a problem if u don't like me to help me.There are always some starters in any field u know.The experimental ones try to help them.So,I am a starter :).If u try to help me,thank u a lot of u collaborativ caracter.Else,it is not time nor place to give me tips Thank u a lot :)

                J 1 Reply Last reply
                0
                • L Luc Pattyn

                  I suggest you read and study this article[^], even if you are using a different version of Visual Studio. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                  I only read formatted code with indentation, so please use PRE tags for code snippets.


                  I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


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

                  Hi, I tried the breakpoint method.I see that the error in the filling of the databox(I verified my TCP/IP connection due to this thread http://www.codeproject.com/Messages/3470516/Re-How-can-check-the-result-of-the-TCP-IP-connecti.aspx[^]) What is the problem??? Thanks

                  1 Reply Last reply
                  0
                  • T Tunisien86

                    Hi, It is not a problem if u don't like me to help me.There are always some starters in any field u know.The experimental ones try to help them.So,I am a starter :).If u try to help me,thank u a lot of u collaborativ caracter.Else,it is not time nor place to give me tips Thank u a lot :)

                    J Offline
                    J Offline
                    johannesnestler
                    wrote on last edited by
                    #9

                    Hi "Starter", After reading your answer, I think I should give you a tip. ;P You seem to be a beginner in programming - otherwise you would know how to debug your code (with or without a debugger...) Many members on codeproject are real experts, ask them if you have a real problem. But before that, learn how to use your tools and language. No one likes the kind of "beginner" unwilling to learn and asking "questions". Developing for a smart device is even more challenging than for a PC platform - (I do it a lot) So if you still have the problem with your combobox and the problem is unspottable during debug - contact me - i will try to help you :rose:

                    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