CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    177

    sql insert double to database

    In my vb.net code, I had the following code:

    Code:
     sql = "INSERT INTO Trn_BranchReportTop ([SellerID],[BranchGLN],[BranchName],[Total]) VALUES('" + Session.Item("UserCompanyID") + "','" + BranchGLN + "','" + Name + "','" + dsPOTrailers.Tables(0).Rows(0).Item("Cost").ToString() + "' )) "
                        objDB.ExecuteNonQuery(sql)
    How should I change so that the dsPOTrailers.Tables(0).Rows(0).Item("Cost").ToString() can be insert to the database which is double datatype in the database.

  2. #2
    Join Date
    Oct 2009
    Posts
    2

    Re: sql insert double to database

    Try something like:

    Code:
    sql = "INSERT INTO Trn_BranchReportTop ([SellerID],[BranchGLN],[BranchName],[Total]) VALUES('" + Session.Item("UserCompanyID") + "','" + BranchGLN + "','" + Name + "','" + CType(dsPOTrailers.Tables(0).Rows(0).Item("Cost").ToString(),Double) + "' )) "

    CType will convert data types. I think this should work for you.

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: sql insert double to database

    You should always use STORED PROCEDURES to interact with the DB. If you have to use a query, make sure that it's a PARAMETERIZED QUERY, to prevent SQL INJECTION
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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