0

when i try to insert a record through .net using oledb it is inserting wrong data

public void param()
{
    OleDbCommand cmd2 = new OleDbCommand("INSERT INTO PARAM_INF(PRM_FRM_DT,PRM_TO_DT) values(to_date('01-Jul-2014'),to_date('01-Jul-2014'))", con) { CommandType = CommandType.Text };
    if (con.State == ConnectionState.Closed)
    {
        con.Open();
    }
    cmd2.ExecuteNonQuery();
    con.Close();
}

result select prm_frm_dt,prm_to_dt from PARAM_INF;

PRM_FRM_DT         PRM_TO_DT        
------------------ ------------------
20-JUL-01 02:00:00 20-JUL-01 02:00:00

But the same insert statement from sqldeveloper or sqlplus result is proper.

select prm_frm_dt,prm_to_dt from PARAM_INF;

PRM_FRM_DT         PRM_TO_DT        
------------------ ------------------
01-JUL-14 12:00:00 01-JUL-14 12:00:00 
3
  • Need help i am seriously in trouble Commented Jul 4, 2014 at 5:14
  • I'm guessing it just how the tools your using the default date format Commented Jul 4, 2014 at 5:21
  • 1
    Parameterized query would properly help; so you don't do text based dates which are subject to the cultures and differences between each server/platform Commented Jul 4, 2014 at 5:31

1 Answer 1

1
public void param()
{
    OleDbCommand cmd2 = new OleDbCommand("INSERT INTO PARAM_INF(PRM_FRM_DT,PRM_TO_DT) values('" + String.Format("{0:yyyy-MMM-dd}", Convert.ToDateTime("01-Jul-2014")) + "','" + String.Format("{0:yyyy-MMM-dd}", Convert.ToDateTime("01-Jul-2014")) + "')", con) { CommandType = CommandType.Text };
    if (con.State == ConnectionState.Closed)
    {
        con.Open();
    }
    cmd2.ExecuteNonQuery();
    con.Close();
}

This will definetly help u... one i had also the same problem...

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.