CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2006
    Location
    Vizag, A.P., INDIA
    Posts
    8

    Question Pls help me.. with this .. pls.. vn.net n oracle..

    hi,
    plz help me quickly.....
    i'm facing a tough situation with my project on vb.net + oracle...

    i've created a table "edt". the data dictionary for it is as follows:

    SQL> describe edt
    Name Type
    -------- ------
    ENAME CHAR(20)
    DT DATE

    and i've written code as follows:
    Code:
    Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
    
    Handles SaveButton.Click
            con.Open()
            MsgBox("connection opened", MsgBoxStyle.OKOnly)
    
            str = "insert into edt values('a'," & CDate(Today()) & ")"
            MessageBox.Show("str:" & str)
    
            mycommand = New OleDbCommand(str, con)
            MsgBox("command set to the connection", MsgBoxStyle.OKOnly)
    
            no = mycommand.ExecuteNonQuery()
            MessageBox.Show("Records inserted: " & no)
    
            con.Close()
            MsgBox("connection closed", MsgBoxStyle.OKOnly)
        End Sub
    
    where 
        Dim con As OleDbConnection
        Dim mycommand As OleDbCommand
    when i run the abv code i see that the command is set to the connection.
    But i get an error at the statement " no = mycommand.ExecuteNonQuery()"
    the error is :

    An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

    Unhandled Exception: System.Data.OleDb.OleDbException: One or more errors occurred during processing of command.
    ORA-00932: inconsistent datatypes: expected DATE got NUMBER

    please help me... i don't understand the error coz the messagebox statement which prints the

    string "str" gives me a correct reply..
    ie. str: insert into edt values('a',9/10/2006)

    waiting for a quick solution to this issue..
    and also let me know what would be the default date format in vb.net.. pls..
    Last edited by cjard; September 11th, 2006 at 05:58 AM.

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow Re: Pls help me.. with this .. pls.. vn.net n oracle..

    str = "insert into edt values('a','" & DateTime.Now.ToShortDateString() & "')"

    In the future, look into using parameterized queries.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Sep 2006
    Location
    Vizag, A.P., INDIA
    Posts
    8

    Re: Pls help me.. with this .. pls.. vn.net n oracle..

    Quote Originally Posted by Craig Gemmill
    str = "insert into edt values('a','" & DateTime.Now.ToShortDateString() & "')"

    In the future, look into using parameterized queries.
    thanks a lot.. for ur reply senor... kaumudi

  4. #4
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Pls help me.. with this .. pls.. vn.net n oracle..

    yuck...

    dont ever rely on implicit parsing of a date from a string. your system might write

    11/08/2006

    meaning 11 aug 2006, but oracle might be on default us date format and treat it as 08 nov 2006


    you MUST put your local date into a string, and then convert it back based on that same string:


    "INSERT INTO evt VALUES('a', to_date('" & DateTime.Now.ToString("yyyyMMdd") &"','yyyymmdd') )"

    for today 11 sep this query would look like:

    INSERT INTO evt VALUES ('a', to_date('20060911', 'yyyymmdd') )





    In blue we have the .NET date format.. it converts this date intoa string in yyyymmdd format. THEN in oracle we have to_date function that turns a string back into date. The format in pink is oracle date format, and oracle knows to parse this string we are putting in as yyyymmdd

    You should ALWAYS be explicit when converting datatypes.. No room for the usual VB type conversion laziness here
    #


    The comment about using parameters is important.. even the process i describe here is not as good as using parameters. USE PARAMETERS.
    Last edited by cjard; September 11th, 2006 at 06:07 AM.
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  5. #5
    Join Date
    Sep 2006
    Location
    Vizag, A.P., INDIA
    Posts
    8

    Smile Re: Pls help me.. with this .. pls.. vn.net n oracle..

    thanks.. i'll surely try this out..
    i m not too good at oracle .. thanks once again..
    kaumudi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured