I am trying to use sql to sum a column in my access database and put the result of this in a text box. The code I have got is the following, but this is coming up with the error below.

Error : Conversion from type 'DBNull' to type 'String' is not valid.

dbCommand = New OleDbCommand
dbCommand.Connection = New OleDbConnection(DataBase)
dbCommand.Connection.Open()
dbCommand.CommandText = "SELECT SUM(TransactionAmount) FROM Transactions WHERE Budget='" & cmbBudget.Text & "'"

Reader = dbCommand.ExecuteReader

While Reader.Read
    TextBox1.Text = Reader.GetValue(0)
End While

The (DataBase) reference is working correctly, as there is a previous SQL command above this one.

Any help much appreciated!!!!!

reader is not declared..

Ah thanks for your reply,but I am confused. What do you mean/ what do I need to do?

Thanks for your reply, I appreciate it :)

Reader = dbCommand.ExecuteReader

Reader declared as what??

Dim Reader as OleDbDataReader = dbCommand.ExecuteReader

TextBox2.Text = reader.GetDouble(0)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.