I have an SQL set up to query a database and find the sum of the amounts in the table, however it's not returning anything, all the data field are correct and also the query is correct in how it should run, I think the issue is passing it to the variable for the data reader, if anyone can correct this I would be greatful.
This is the code, I think it is something to do with the datareader:
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---
System.Data.OleDb.OleDbException: Syntax error in FROM clause. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at HSBC.CheckBal(Int64 accountnumber) at HSBC.CheckBalance(Int64 accountnumber) --- End of inner exception stack trace ---
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.OleDb.OleDbException: Syntax error in FROM clause. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at HSBC.CheckBal(Int64 accountnumber) at HSBC.CheckBalance(Int64 accountnumber) --- End of inner exception stack trace ---
This is the code that is being called.
'Creates a service web method
Private Function CheckBal(ByVal accountnumber As Long) As String
'Database(drivers, connections And commands)
Dim BalanceDr As OleDbDataReader
Dim BalanceConn As OleDbConnection
Dim BalanceCmd As OleDbCommand
'Database connection string
Dim Connx As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../database/HSBC.mdb") & ";"
'SQL
Dim SQL As String = "SELECT Transaction_Amount FROM Transaction WHERE Account_Number =" & accountnumber & ";"
Dim bal As String
'Open the connection to the database
BalanceConn = New OleDbConnection(Connx)
BalanceConn.Open()
BalanceCmd = New OleDbCommand(SQL, BalanceConn)
'Create a DataReader that will return information.
BalanceDr = _
BalanceCmd.ExecuteReader(CommandBehavior.CloseConnection)
If BalanceDr.Read() Then
'A row was returned
bal = BalanceDr(0)
Else
'A row was not returned
bal = "No Balance For Account Found"
End If
BalanceDr.Close()
Return SQL
End Function
End Class