Need help !!
-
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
-
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
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++
-
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
-
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++
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.
-
Add
.ToString()
to your integer types. For example, instead oftempID
usetempID.ToString()
.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.
-
Add
.ToString()
to your integer types. For example, instead oftempID
usetempID.ToString()
.That works by itself, actually Christian Graus - Microsoft MVP - C++
-
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.
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++
-
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