triplebd69
asked on
C# insert into Oracle
I am new at this and need help with what I hope is a simple question. I have a C# app that needs to insert records into an Oracle db. The code I have runs without error but does not actually insert a record. Here is my code so far.
string eEmpID = tbEmpID.Text;
string eFName = tbFName.Text;
string eLName = tbLName.Text;
string eEmail = tbEmail.Text;
string ePhone = tbPhone.Text;
string eHireDate = " ";
string eJobID = ddlJobID.SelectedValue;
string eGrade = ddlGrade.SelectedValue;
using (OracleConnection con = new OracleConnection(Configura tion.oConn ))
{
con.Open();
string oCMD = "insert into RANDRAPP.EMPLOYEES(EMPLOYE E_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY, MANAGER_ID, DEPT_ID, TIME_REMAINING) VALUES (eEmpID, eFName, eLName, eEmail, ePhone, eHire_Date, eJobID, eGrade)";
OracleCommand cmd = new OracleCommand(oCMD, con);
}
string eEmpID = tbEmpID.Text;
string eFName = tbFName.Text;
string eLName = tbLName.Text;
string eEmail = tbEmail.Text;
string ePhone = tbPhone.Text;
string eHireDate = " ";
string eJobID = ddlJobID.SelectedValue;
string eGrade = ddlGrade.SelectedValue;
using (OracleConnection con = new OracleConnection(Configura
{
con.Open();
string oCMD = "insert into RANDRAPP.EMPLOYEES(EMPLOYE
OracleCommand cmd = new OracleCommand(oCMD, con);
}
ASKER
Sorry I must have cut that off it is in the code.
Then that should be all you need. If the SQL threw an error it would come back to you as an exception. Not sure what else could be going on. Do you have a try block anywhere that could be catching the exception?
ASKER
Took it out. Is there anything to do to get the value of these variables? Do they need quotes or something?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Do I also need to a value for each column in the table?
Yes, you need a value for each column in the list of fields (in the same order as well). I didn't catch that in your SQL either.
ASKER
Thanks so much you have been a great help!
try
OracleCommand cmd = new OracleCommand(oCMD, con);
cmd.ExecuteNonQuery();