Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Need help !!

Need help !!

Scheduled Pinned Locked Moved Visual Basic
help
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 1934105
    wrote on last edited by
    #1

    I'm having problem on the following code: Public Class ExpenseEntity Public Function saveNewExpense(ByVal tempName As String, _ ByVal tempType As String, _ ByVal tempAmt As Integer, ByVal tempCatID As Integer) Dim cnNewEx As SqlCeConnection = New SqlCeConnection( _ "Data Source=\My Documents\PFMS.sdf; password=9EbK63Lj") Dim SQLNewEx As String Dim cmdSQLEx As SqlCeCommand Dim getEName As SqlCeDataReader Dim tempID As Integer SQLNewEx = "INSERT INTO ExpenseDetail(expenseID, catID, eType, eAmount) " & _ "VALUES (" + tempID + ", " + tempCatID + ", '" + tempType + "', " + tempAmt + ")" cmdSQLEx = New SqlCeCommand(SQLNewEx, cnNewEx) cmdSQLEx.CommandType = CommandType.Text cmdSQLEx.ExecuteNonQuery() cmdSQLEx.Dispose() cnNewEx.Close() I receive the error as: "An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll Additional information: InvalidCastException" Please help... thanks in advance

    C R A 3 Replies Last reply
    0
    • U User 1934105

      I'm having problem on the following code: Public Class ExpenseEntity Public Function saveNewExpense(ByVal tempName As String, _ ByVal tempType As String, _ ByVal tempAmt As Integer, ByVal tempCatID As Integer) Dim cnNewEx As SqlCeConnection = New SqlCeConnection( _ "Data Source=\My Documents\PFMS.sdf; password=9EbK63Lj") Dim SQLNewEx As String Dim cmdSQLEx As SqlCeCommand Dim getEName As SqlCeDataReader Dim tempID As Integer SQLNewEx = "INSERT INTO ExpenseDetail(expenseID, catID, eType, eAmount) " & _ "VALUES (" + tempID + ", " + tempCatID + ", '" + tempType + "', " + tempAmt + ")" cmdSQLEx = New SqlCeCommand(SQLNewEx, cnNewEx) cmdSQLEx.CommandType = CommandType.Text cmdSQLEx.ExecuteNonQuery() cmdSQLEx.Dispose() cnNewEx.Close() I receive the error as: "An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll Additional information: InvalidCastException" Please help... thanks in advance

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Lot of code here. which line has the exception, or didn't you bother to step through in the debugger ? I'd imagine that when you set SQLNewEx, that one of the objects you're passing in does not convert to string by itself. Christian Graus - Microsoft MVP - C++

      U 1 Reply Last reply
      0
      • U User 1934105

        I'm having problem on the following code: Public Class ExpenseEntity Public Function saveNewExpense(ByVal tempName As String, _ ByVal tempType As String, _ ByVal tempAmt As Integer, ByVal tempCatID As Integer) Dim cnNewEx As SqlCeConnection = New SqlCeConnection( _ "Data Source=\My Documents\PFMS.sdf; password=9EbK63Lj") Dim SQLNewEx As String Dim cmdSQLEx As SqlCeCommand Dim getEName As SqlCeDataReader Dim tempID As Integer SQLNewEx = "INSERT INTO ExpenseDetail(expenseID, catID, eType, eAmount) " & _ "VALUES (" + tempID + ", " + tempCatID + ", '" + tempType + "', " + tempAmt + ")" cmdSQLEx = New SqlCeCommand(SQLNewEx, cnNewEx) cmdSQLEx.CommandType = CommandType.Text cmdSQLEx.ExecuteNonQuery() cmdSQLEx.Dispose() cnNewEx.Close() I receive the error as: "An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll Additional information: InvalidCastException" Please help... thanks in advance

        R Offline
        R Offline
        rudy net
        wrote on last edited by
        #3

        Add .ToString() to your integer types. For example, instead of tempID use tempID.ToString().

        U C 2 Replies Last reply
        0
        • C Christian Graus

          Lot of code here. which line has the exception, or didn't you bother to step through in the debugger ? I'd imagine that when you set SQLNewEx, that one of the objects you're passing in does not convert to string by itself. Christian Graus - Microsoft MVP - C++

          U Offline
          U Offline
          User 1934105
          wrote on last edited by
          #4

          Thanks for your reply.... Some how I get to manage solve the error through out the night. The exception is occur at the last SQL statement.

          C 1 Reply Last reply
          0
          • R rudy net

            Add .ToString() to your integer types. For example, instead of tempID use tempID.ToString().

            U Offline
            U Offline
            User 1934105
            wrote on last edited by
            #5

            Thanks for your reply.... Some how I get to manage solve the error through out the night. The problem solve when replace '+' with '&' in SQL statement.

            1 Reply Last reply
            0
            • R rudy net

              Add .ToString() to your integer types. For example, instead of tempID use tempID.ToString().

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              That works by itself, actually Christian Graus - Microsoft MVP - C++

              1 Reply Last reply
              0
              • U User 1934105

                Thanks for your reply.... Some how I get to manage solve the error through out the night. The exception is occur at the last SQL statement.

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                yes, that's where I said. That means sometimes the variables you're passing through are either null, or some type that can't be converted to string. You need to write some code to protect against bad values, and insert an appropriate value into your SQL. Doing it as a stored procedure would be even better. It seems mostly in VB land that people ignore this basic design step. Christian Graus - Microsoft MVP - C++

                1 Reply Last reply
                0
                • U User 1934105

                  I'm having problem on the following code: Public Class ExpenseEntity Public Function saveNewExpense(ByVal tempName As String, _ ByVal tempType As String, _ ByVal tempAmt As Integer, ByVal tempCatID As Integer) Dim cnNewEx As SqlCeConnection = New SqlCeConnection( _ "Data Source=\My Documents\PFMS.sdf; password=9EbK63Lj") Dim SQLNewEx As String Dim cmdSQLEx As SqlCeCommand Dim getEName As SqlCeDataReader Dim tempID As Integer SQLNewEx = "INSERT INTO ExpenseDetail(expenseID, catID, eType, eAmount) " & _ "VALUES (" + tempID + ", " + tempCatID + ", '" + tempType + "', " + tempAmt + ")" cmdSQLEx = New SqlCeCommand(SQLNewEx, cnNewEx) cmdSQLEx.CommandType = CommandType.Text cmdSQLEx.ExecuteNonQuery() cmdSQLEx.Dispose() cnNewEx.Close() I receive the error as: "An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll Additional information: InvalidCastException" Please help... thanks in advance

                  A Offline
                  A Offline
                  albCode
                  wrote on last edited by
                  #8

                  You should say in the end to datagrid to bind itself. DataGrid1.DataBind()

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups