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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Record Not Insert

Record Not Insert

Scheduled Pinned Locked Moved C#
oraclesysadmintutorial
8 Posts 5 Posters 2 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.
  • M Offline
    M Offline
    mjawadkhatri
    wrote on last edited by
    #1

    Hi please check my coding and guide me why record not insert my coding is OdbcConnection cn; OdbcCommand cmd; OdbcDataReader odr; string MyString; MyString = "Select empid , sysdte from timemgmt"; if (radioin.Checked == true) { cn = new OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=orcl8i;UID=itehad;PWD=creative;"); cmd = new OdbcCommand(MyString, cn); cn.Open(); cmd.CommandText = "Select empid , sysdte from timemgmt where empid = '"+textBox1.Text+"' and sysdte ='"+label19.Text+"'"; //MessageBox.Show("Connected"); //cmd.CommandText = "select empid,sysdteinsert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')";//,'" + label18.Text + "','" + label18.Text + "')"; //MessageBox.Show(cmd.CommandText); //cmd.ExecuteNonQuery(); odr = cmd.ExecuteReader(); while (odr.Read()) { if (textBox1.Text == (odr["empid"].ToString()) && label19.Text == (odr["sysdte"]).ToString()) { MessageBox.Show("You Already IN this ID Today"); } else { cmd.CommandText = "insert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; } } cn.Close();

    M T P 3 Replies Last reply
    0
    • M mjawadkhatri

      Hi please check my coding and guide me why record not insert my coding is OdbcConnection cn; OdbcCommand cmd; OdbcDataReader odr; string MyString; MyString = "Select empid , sysdte from timemgmt"; if (radioin.Checked == true) { cn = new OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=orcl8i;UID=itehad;PWD=creative;"); cmd = new OdbcCommand(MyString, cn); cn.Open(); cmd.CommandText = "Select empid , sysdte from timemgmt where empid = '"+textBox1.Text+"' and sysdte ='"+label19.Text+"'"; //MessageBox.Show("Connected"); //cmd.CommandText = "select empid,sysdteinsert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')";//,'" + label18.Text + "','" + label18.Text + "')"; //MessageBox.Show(cmd.CommandText); //cmd.ExecuteNonQuery(); odr = cmd.ExecuteReader(); while (odr.Read()) { if (textBox1.Text == (odr["empid"].ToString()) && label19.Text == (odr["sysdte"]).ToString()) { MessageBox.Show("You Already IN this ID Today"); } else { cmd.CommandText = "insert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; } } cn.Close();

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      It would be helpful if you posted the error generated! This assumes there are only 4 field in the table. cmd.CommandText = "insert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; If there are more you need cmd.CommandText = "insert into timemgmt (field1, field2, field3, field4) values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')";

      Never underestimate the power of human stupidity RAH

      M 1 Reply Last reply
      0
      • M Mycroft Holmes

        It would be helpful if you posted the error generated! This assumes there are only 4 field in the table. cmd.CommandText = "insert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; If there are more you need cmd.CommandText = "insert into timemgmt (field1, field2, field3, field4) values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')";

        Never underestimate the power of human stupidity RAH

        M Offline
        M Offline
        mjawadkhatri
        wrote on last edited by
        #3

        I give feild name like this cmd.CommandText = "insert into timemgmt values(empid,sysdte,intime,outtime)('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; no record Insert :( And no error show please guyz help me

        K 1 Reply Last reply
        0
        • M mjawadkhatri

          I give feild name like this cmd.CommandText = "insert into timemgmt values(empid,sysdte,intime,outtime)('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; no record Insert :( And no error show please guyz help me

          K Offline
          K Offline
          K0306
          wrote on last edited by
          #4

          There is a error in insert statement try this

          cmd.CommandText = "insert into timemgmt(empid,sysdte,intime,outtime) values ('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')";

          Regards, Karthik K...

          M 1 Reply Last reply
          0
          • K K0306

            There is a error in insert statement try this

            cmd.CommandText = "insert into timemgmt(empid,sysdte,intime,outtime) values ('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')";

            Regards, Karthik K...

            M Offline
            M Offline
            mjawadkhatri
            wrote on last edited by
            #5

            No my problem is not solve :( ok tell me how i search record in oracle database if record find record not save else save record i code this for search record cmd.CommandText = "Select empid , sysdte from timemgmt where empid = '"+textBox1.Text+"' and sysdte ='"+label19.Text+"'"; then i create condition like this while (odr.Read()) { if (textBox1.Text == (odr["empid"].ToString()) && label19.Text == (odr["sysdte"]).ToString()) { MessageBox.Show("You Already IN this ID Today"); } else { cmd.CommandText = "insert into timemgmt values(empid, sysdte, intime, outtime)('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; cmd.ExecuteNonQuery(); }

            K 1 Reply Last reply
            0
            • M mjawadkhatri

              Hi please check my coding and guide me why record not insert my coding is OdbcConnection cn; OdbcCommand cmd; OdbcDataReader odr; string MyString; MyString = "Select empid , sysdte from timemgmt"; if (radioin.Checked == true) { cn = new OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=orcl8i;UID=itehad;PWD=creative;"); cmd = new OdbcCommand(MyString, cn); cn.Open(); cmd.CommandText = "Select empid , sysdte from timemgmt where empid = '"+textBox1.Text+"' and sysdte ='"+label19.Text+"'"; //MessageBox.Show("Connected"); //cmd.CommandText = "select empid,sysdteinsert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')";//,'" + label18.Text + "','" + label18.Text + "')"; //MessageBox.Show(cmd.CommandText); //cmd.ExecuteNonQuery(); odr = cmd.ExecuteReader(); while (odr.Read()) { if (textBox1.Text == (odr["empid"].ToString()) && label19.Text == (odr["sysdte"]).ToString()) { MessageBox.Show("You Already IN this ID Today"); } else { cmd.CommandText = "insert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; } } cn.Close();

              T Offline
              T Offline
              Tom Deketelaere
              wrote on last edited by
              #6

              I already told you to use the 'code block' tags when posting code (see here[^] ) I also already told you to use parameters (to prevent sql-injunctions). Not only are they safer they will also prevent a lot of errors.

              1 Reply Last reply
              0
              • M mjawadkhatri

                Hi please check my coding and guide me why record not insert my coding is OdbcConnection cn; OdbcCommand cmd; OdbcDataReader odr; string MyString; MyString = "Select empid , sysdte from timemgmt"; if (radioin.Checked == true) { cn = new OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=orcl8i;UID=itehad;PWD=creative;"); cmd = new OdbcCommand(MyString, cn); cn.Open(); cmd.CommandText = "Select empid , sysdte from timemgmt where empid = '"+textBox1.Text+"' and sysdte ='"+label19.Text+"'"; //MessageBox.Show("Connected"); //cmd.CommandText = "select empid,sysdteinsert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')";//,'" + label18.Text + "','" + label18.Text + "')"; //MessageBox.Show(cmd.CommandText); //cmd.ExecuteNonQuery(); odr = cmd.ExecuteReader(); while (odr.Read()) { if (textBox1.Text == (odr["empid"].ToString()) && label19.Text == (odr["sysdte"]).ToString()) { MessageBox.Show("You Already IN this ID Today"); } else { cmd.CommandText = "insert into timemgmt values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; } } cn.Close();

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

                Where to start?

                1. Give your variables meaningful names. At a glance, what does textBox1 do?
                2. Your code is wide open to a SQL Injection attack. You need to look into using parameterised queries here.
                3. Your insert statement does nothing. You create the command text and then close the connection - you need to execute the command using cmd.ExecuteNonQuery();
                4. You have no exception handling. What happens if you can't connect the database, for instance?

                If you had bothered to debug your code, you would have found the problem out in an instant. Learning to debug is one of the most valuable lessons you can master as a developer, and you should learn how to do it before too much longer.

                "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
                • M mjawadkhatri

                  No my problem is not solve :( ok tell me how i search record in oracle database if record find record not save else save record i code this for search record cmd.CommandText = "Select empid , sysdte from timemgmt where empid = '"+textBox1.Text+"' and sysdte ='"+label19.Text+"'"; then i create condition like this while (odr.Read()) { if (textBox1.Text == (odr["empid"].ToString()) && label19.Text == (odr["sysdte"]).ToString()) { MessageBox.Show("You Already IN this ID Today"); } else { cmd.CommandText = "insert into timemgmt values(empid, sysdte, intime, outtime)('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')"; cmd.ExecuteNonQuery(); }

                  K Offline
                  K Offline
                  K0306
                  wrote on last edited by
                  #8

                  mjawadkhatri wrote:

                  cmd.CommandText = "Select empid ,sysdte from timemgmt where empid = '" + textBox1.Text + "' and sysdte ='" + label19.Text + "'";

                  your search query is ok. After that use like this way,

                  if(odr.read())
                  {
                  MessageBox.Show("You Already IN this ID Today");
                  }
                  else
                  {
                  cmd.CommandText = "insert into timemgmt empid, sysdte, intime, outtime) values('" + textBox1.Text + "','" + label19.Text + "','" + label18.Text + "','" + label18.Text + "')";
                  cmd.ExecuteNonQuery();
                  }

                  Try the above code.Use the Breakpoints and try to rectify where the error comes.

                  Regards, Karthik K...

                  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