Insert Today into an oracle tablehttp://forums.asp.net/t/1779988.aspx/1?Insert+Today+into+an+oracle+tableMon, 19 Mar 2012 17:01:12 -040017799884878460http://forums.asp.net/p/1779988/4878460.aspx/1?Insert+Today+into+an+oracle+tableInsert Today into an oracle table <p>This is driving me crazy!&nbsp; I keep on getting an error at the date part of the insert statement</p> <h2>ORA-00932: inconsistent datatypes: expected DATE got NUMBER</h2> <p>The data type in the oracle table is Date(7)</p> <p>how do I fix this?</p> <p>Thanks</p> <pre class="prettyprint">oConnection = New OracleConnection(&quot;Data Source= ;User ID=;Password=;&quot;) oConnection.Open() oCommand.Connection = oConnection oCommand.CommandText = &quot;INSERT INTO MAPS.GIS(ENTRYDATE,USERID,JOB_NUMBER,ENTRY_TYPE,CHANGE_DESCRIPTION) VALUES(&quot; &amp; <strong>Today</strong> &amp; &quot;,'&quot; &amp; &quot;USERID', &quot; &amp; txtJO.Text &amp; &quot;,'&quot; &amp; txtType.Text &amp; &quot;','&quot; &amp; txtDesc.Text &amp; &quot;')&quot; oReader = oCommand.ExecuteReader()</pre> 2012-03-13T21:58:23-04:004880990http://forums.asp.net/p/1779988/4880990.aspx/1?Re+Insert+Today+into+an+oracle+tableRe: Insert Today into an oracle table <p>In Your query&nbsp; use &nbsp;<em>SYSDATE instead of Today .<em>SYSDATE is used today dateand time in oracle</em></em></p> 2012-03-15T04:58:41-04:004881005http://forums.asp.net/p/1779988/4881005.aspx/1?Re+Insert+Today+into+an+oracle+tableRe: Insert Today into an oracle table <p>Use SYSDATE instead of <strong><span class="typ">Today</span></strong></p> <p><strong><span class="typ"><br> </span></strong></p> <pre class="prettyprint">&quot;INSERT INTO MAPS.GIS(ENTRYDATE,USERID,JOB_NUMBER,ENTRY_TYPE,CHANGE_DESCRIPTION) VALUES(&quot;SYSDATE &quot;,'&quot; &amp; &quot;USERID', &quot; &amp; txtJO.Text &amp; &quot;,'&quot; &amp; txtType.Text &amp; &quot;','&quot; &amp; txtDesc.Text &amp; &quot;')&quot; Regards,</pre> <p><strong><span class="typ"><br> </span></strong></p> <p></p> 2012-03-15T05:09:48-04:004884373http://forums.asp.net/p/1779988/4884373.aspx/1?Re+Insert+Today+into+an+oracle+tableRe: Insert Today into an oracle table <p>SYSDATE is not working ... I get an err</p> <p></p> <h2><i>Compilation Error</i></h2> <p><span face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif " style="font-family:Arial,Helvetica,Geneva,SunSans-Regular,sans-serif"><b>Description: </b>An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. <br> <br> <b>Compiler Error Message: </b>BC30451: Name 'Sysdate' is not declared.<br> </span></p> 2012-03-16T17:16:03-04:004886435http://forums.asp.net/p/1779988/4886435.aspx/1?Re+Insert+Today+into+an+oracle+tableRe: Insert Today into an oracle table <p>You should use Oracle Parameters and BIND variable to pass values into your INSERT statement</p> <p>SYSDATE error is likely indirect effect of other failures</p> <p>example</p> <pre class="prettyprint">Imports System.Xml.Linq.XElement Public Shared Sub updateUnitsActiveFlag(ByVal decQuantity As Decimal) ' Insert Quantity into new row Units table' Dim OraConnStr As String = ConfigurationManager.ConnectionStrings(&quot;{YourOraConnStrName}&quot;).ConnectionString Try Dim SQL = &lt;SQL&gt; INSERT INTO {YOURSCHEMANAME}.UNITS (UNITS_SEQ, QUANTITY, DATE_CLOSED, DATE_TODAY) VALUES (UNIT_SEQ.NextVal, :BindVarQuantity, :DateClosed, SYSDATE) &lt;/SQL&gt; Using conn As New OracleConnection(OraConnStr) Using cmd As New OracleCommand(SQL.Value, conn) cmd.Parameters.Clear() cmd.Parameters.Add(&quot;BindVarQuantity&quot;, OracleDbType.Decimal, decQuantity, ParameterDirection.Input) cmd.Parameters.Add(&quot;DateClosed&quot;, OracleDbType.Date, dateDateClosed, ParameterDirection.Input) conn.Open() cmd.ExecuteNonQuery() End Using End Using Catch ex As Exception 'you exception handling code</pre> <pre class="prettyprint"> End Try End Sub</pre> <p>&nbsp;</p> 2012-03-19T01:31:52-04:004886438http://forums.asp.net/p/1779988/4886438.aspx/1?Re+Insert+Today+into+an+oracle+tableRe: Insert Today into an oracle table <p></p> <blockquote><span class="icon-blockquote"></span> <h4>greenheck1</h4> <p></p> <p>SYSDATE is not working ... I get an err</p> <p></p> <h2><i>Compilation Error</i></h2> <p><span face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif " style="font-family:Arial,Helvetica,Geneva,SunSans-Regular,sans-serif"><b>Description: </b>An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. <br> <br> <b>Compiler Error Message: </b>BC30451: Name 'Sysdate' is not declared.<br> </span></p> <p></p> </blockquote> <p></p> <p>Sysdate is an oracle function that returns the current date and time.&nbsp; It is not a dot net variable that you pass to oracle.</p> 2012-03-19T01:34:26-04:004887979http://forums.asp.net/p/1779988/4887979.aspx/1?Re+Insert+Today+into+an+oracle+tableRe: Insert Today into an oracle table <p>Thank you guys for your posts</p> <p></p> <p>I tried the oracle parameters but i got a whole bunch of errs ... so I tried the below instead and it worked!!</p> <p></p> <pre class="prettyprint">String.Format(&quot;{0:dd-MMM-yyyy}&quot;, System.DateTime.Now) Thanks all</pre> 2012-03-19T17:01:12-04:00