Solved

C#, Oracle .NET Update Datefield

Posted on 2009-05-04
2
864 Views
Last Modified: 2012-05-06
Hello experts,

I am trying update one of my oracle table. one field is a datatime. How do I do that?

PPeriodStart - it is datetime
PPeriodEnd - it is datetime


                    OracleTransaction myOracleTransaction = Program.g_DBO.cnDB.BeginTransaction(); ;
                    OracleCommand oraCmd = new OracleCommand();
                    try
                    {
                        sqlText = "UPDATE pc.pcy set " +
                                " PAC = " + PcyAss + ", " +
                                " PPeriodStart = '" + To_date(PPeriodStart, "yyyymmdd") + "', " +
                                " PPeriodEnd = '" + To_date(PPeriodEnd, "yyyymmdd") + "'
                                " WHERE CoverageID = " + CoverageID + "";
                        oraCmd.Connection = Program.g_DBO.cnDB;
                        oraCmd.CommandType = CommandType.Text;
                        oraCmd.CommandText = sqlText;
                        oraCmd.ExecuteNonQuery();
                        myOracleTransaction.Commit();
                        return true;
0
Comment
Question by:listings_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
mrjoltcola earned 500 total points
ID: 24295629
You can use bind variables, and add parameters via OracleCommand.Parameters.Add

Somethign like this (untested), I don't have my VS up with a project to test.

Also read:


http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracleparameter.aspx

http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28844/building_odp.htm#CEGCGDAB

http://download.oracle.com/docs/html/B28089_01/OracleParameterClass.htm#i1010881

                    OracleTransaction myOracleTransaction = Program.g_DBO.cnDB.BeginTransaction(); ;
                    OracleCommand oraCmd = new OracleCommand();
                    try
                    {
                        sqlText = "UPDATE pc.pcy set PAC = " + PcyAss + ", " +  // I would also convert PcyAss to a bind parameter
                                " PPeriodStart = :PPeriodStart, " +
                                " PPeriodEnd = :PPeriodEnd " +
                                " WHERE CoverageID = :CoverageID ";
                        oraCmd.Connection = Program.g_DBO.cnDB;
                        oraCmd.CommandType = CommandType.Text;
                        oraCmd.CommandText = sqlText;
                        oraCmd.Parameters.Add("PPeriodStart", OracleType.Date, PPeriodStart, ParameterDirection.Input);
                        oraCmd.Parameters.Add("PPeriodEnd", OracleType.Date, PPeriodEnd, ParameterDirection.Input);
                        oraCmd.Parameters.Add("CoverageID", OracleType.Int, CoverageID, ParameterDirection.Input);
                        oraCmd.ExecuteNonQuery();
                        myOracleTransaction.Commit();
                        return true;

Open in new window

0
 

Author Comment

by:listings_
ID: 24297615
Thanks mrjoltcola.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question