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. problem when launching application

problem when launching application

Scheduled Pinned Locked Moved C#
helpdatabase
14 Posts 4 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.
  • OriginalGriffO OriginalGriff

    Firstly, tell us such things when you post a question - remember that we can't see your screen, access your HDD, or read your mind! :laugh: So - you open a connection, but you don't do anything else with it? either add:

    cmd.Connection = connection;

    Or use the syntax I showed in my previous answer. In the case of your code, I'd do this instead:

        private void textBox1\_KeyUp(object sender, KeyEventArgs e)
        {
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter("SELECT informix.thisent.etb FROM informix.thisent", connection);
            da.Fill(dt);
            dataGridView1.DataSource = dt;
        }
    

    As the DataAdapter will open and close the connection for you. BTW: Please, don;t use Visual Studio default names for controls! textBox1 doesn;t mean anything to anyone reading this code, where as searchForText makes it much more obvious what you are doing. It's not a problem when your apps are tiny, but when the number of controls starts to rise it becomes a real PITA and can cause a lot of mistakes. It's well worth getting into the habit of changing the name immediately you create the control as (compared to the five or six seconds extra it takes) it can save a heck of a lot of time later!

    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

    I Offline
    I Offline
    Ibrahim elh
    wrote on last edited by
    #5

    Thank you for your interesting response . I do not have to eureur . I would change the names of the textbox I put a textbox to get the value in the db and display in the DataGridView . But when I run the application and I try to put a value in the text box the application starts to load and just stand . its starts to load but without result and it crashes :sigh: Thank you :)

    OriginalGriffO 1 Reply Last reply
    0
    • I Ibrahim elh

      Thank you for your interesting response . I do not have to eureur . I would change the names of the textbox I put a textbox to get the value in the db and display in the DataGridView . But when I run the application and I try to put a value in the text box the application starts to load and just stand . its starts to load but without result and it crashes :sigh: Thank you :)

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #6

      Have you had a good look with the debugger?

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      I 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Have you had a good look with the debugger?

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

        I Offline
        I Offline
        Ibrahim elh
        wrote on last edited by
        #7

        there is no error , I think it's because he has too much data there.

        OriginalGriffO 1 Reply Last reply
        0
        • I Ibrahim elh

          there is no error , I think it's because he has too much data there.

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #8

          So restrict the amount it is returning:

          SELECT TOP 100 informix.thisent.etb FROM informix.thisent

          would at least confirm that is the problem.

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          I 1 Reply Last reply
          0
          • I Ibrahim elh

            I put :

            private void textBox1_KeyUp(object sender, KeyEventArgs e)
            {
            connection.Open();
            //Assignes la propriété Connection de ta SqlCommand à ta SqlConnection (connection) avant de l'ouvrir.

                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "Select informix.thisent.etb from informix.thisent";
                    
                    cmd.ExecuteNonQuery();
                    DataTable dt = new DataTable();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                    dataGridView1.DataSource = dt;
                    connection.Close();
            
            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #9

            Are you actually connecting to Informix here? If you are, I think you'll probably find that you are trying to use the SQL Server data classes to access them - hence the reason the connection doesn't open.

            I 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              So restrict the amount it is returning:

              SELECT TOP 100 informix.thisent.etb FROM informix.thisent

              would at least confirm that is the problem.

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

              I Offline
              I Offline
              Ibrahim elh
              wrote on last edited by
              #10

              I have another error :( :( :( :( : An unhandled exception of type ' System.Data.Odbc.OdbcException ' occurred in System.Data.dll Additional Information : ERROR [ 42000 ] [ SCO Vision ] [ODBC Driver] SQL Server Retriever - Syntax error near '100

              1 Reply Last reply
              0
              • P Pete OHanlon

                Are you actually connecting to Informix here? If you are, I think you'll probably find that you are trying to use the SQL Server data classes to access them - hence the reason the connection doesn't open.

                I Offline
                I Offline
                Ibrahim elh
                wrote on last edited by
                #11

                I put another code :

                private void Form1_Load(object sender, EventArgs e)
                {
                try
                {
                con = new OdbcConnection();
                con.ConnectionString = @"Dsn=***;Driver={SCO Vision ODBC};uid=***;Pwd=****";
                con.Open();
                con);
                adap = new OdbcDataAdapter("SELECT TOP 100 informix.thisent.etb FROM informix.thisent", con);
                Ds = new System.Data.DataSet();
                adap.Fill(Ds, "ibr");
                dataGridView1.DataSource = Ds.Tables[0];
                }
                catch (Exception ex)
                {
                MessageBox.Show("ERREUR\n" + ex.Message, "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                BUT I have an error : error [42S22][SCO VISION][ODBC DRIVER][INFORMIX] column (top) not found in any table in the query .

                P 1 Reply Last reply
                0
                • I Ibrahim elh

                  I put another code :

                  private void Form1_Load(object sender, EventArgs e)
                  {
                  try
                  {
                  con = new OdbcConnection();
                  con.ConnectionString = @"Dsn=***;Driver={SCO Vision ODBC};uid=***;Pwd=****";
                  con.Open();
                  con);
                  adap = new OdbcDataAdapter("SELECT TOP 100 informix.thisent.etb FROM informix.thisent", con);
                  Ds = new System.Data.DataSet();
                  adap.Fill(Ds, "ibr");
                  dataGridView1.DataSource = Ds.Tables[0];
                  }
                  catch (Exception ex)
                  {
                  MessageBox.Show("ERREUR\n" + ex.Message, "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  }

                  BUT I have an error : error [42S22][SCO VISION][ODBC DRIVER][INFORMIX] column (top) not found in any table in the query .

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

                  That's because you are using illegal syntax in Informix. My Informix is a bit rusty, but I'm pretty sure you're meant to use SELECT FIRST 100 ... to get the data back. TOP is a SQL Server keyword.

                  I 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    That's because you are using illegal syntax in Informix. My Informix is a bit rusty, but I'm pretty sure you're meant to use SELECT FIRST 100 ... to get the data back. TOP is a SQL Server keyword.

                    I Offline
                    I Offline
                    Ibrahim elh
                    wrote on last edited by
                    #13

                    It's good, I would give you a gift when you come in France ;P ;P ;P ;P ;P

                    1 Reply Last reply
                    0
                    • I Ibrahim elh

                      hello : I am trying to develop an application in C # I made my connection string to connect to the database but when I launch an error message saying : An unhandled exception of type ' System.InvalidOperationException exception 'occurred in System.Data.dll Additional information: ExecuteNonQuery : the Connection property has not been initialized. Thank you :)

                      E Offline
                      E Offline
                      eljainc
                      wrote on last edited by
                      #14

                      You must instantiate the connection and then open a database. Here is an example OdbcConnection cnn = new OdbcConnection("DSN=DATABASE"); cnn.Open(); The parameter in this case would be the connection string. There are many different ways the connection string may be formed. It depends partially on which database type you are opening (SQL Server, MsAccess, Oracle, etc)

                      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