0

I am trying to add a new record into the database.

The code was initially

rsGroup.Open(ftSQL, Global.gADOConnection, false);
rsGroup.AddNew();

rsGroup["PANELIST_NUM"] = flPanelistNum;
rsGroup["USER_CREATED"] = Global.glUserNumberID;

With the initial error happening on the rsGroup.AddNew() being - Column PANELIST_NUM does not allow nulls.
This is because it is the Primary Key.

To fix this I tried to use an insert method-

strInsert1 = "INSERT INTO PANELIST_HEADER (PANELIST_NUM, USER_CREATED) VALUES (" + flPanelistNumber + "," + Global.glUserNumberID + ")";

System.Data.OracleClient.OracleCommand cmdCommand = new
System.Data.OracleClient.OracleCommand();

cmdCommand.CommandText = strInsert1;
cmdCommand.Connection = Global.gADOConnection;
cmdCommand.ExecuteNonQuery();

When I run this I do not get an error but it goes on in an infinite loop and never makes it to the next line of code after the ExecuteNonQuery Command. Is there a reason why it is stuck in a loop and/or is there another way for me to successfully add this record to the database?

6
  • Would you be better off using an ORM, like Entity Framework or NHibernate? Commented Aug 7, 2012 at 20:09
  • Are you sure your connection is open? It sounds like that is the problem. Also have you tried placing a try/catch around the code to see if any errors are occuring? Commented Aug 7, 2012 at 20:20
  • What loop? Maybe the table is locked. Can you try to restart the server to make sure all locks are cleared? Commented Aug 7, 2012 at 20:20
  • I am not familiar with ORM. Justin, it is in a try catch loop. It simply hits the ExecuteNonQuery and then runs that line but never finishes. So I never get an error it just acts like it is running but it never finishes or moves on. Although I have ran it in SQL developer where it works. And I believe the connection is open as I have used that connection before in this form where it works fine. Commented Aug 7, 2012 at 20:25
  • Your are vulnerable to SQL injections. Please use parameters instead of directly inserting your potential unsafe user input into the SQL statement! Also note that the System.Data.OracleClient namespace is deprecated. You should use the provider offered by Oracle! Commented Aug 7, 2012 at 20:29

1 Answer 1

1

IF the ExecuteNonQuery method is hanging, it almost sounds like a lock is being taken on the database (or a lock from a previous invocation hasn't been released). It really can't be an infinite loop, as your code (at least the fragment you posted) isn't looping.

Also, it would be very advisable to parameterize your INSERT statement, because the code as illustrated would be vulnerable to SQL injection attacks.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.