I Have A Table with the following Columns
ID(integer)
mat_id(integer)
move_date(Date/Time)
rec_num (Short text)
Qty (number(double))
I have made a connection programmatically and tried a query the code is as below
Public Class ViewMatInfo
Dim ConStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\RMM\RMMDB.mdb;Persist Security Info=True"
Dim Conn As New OleDb.OleDbConnection(ConStr)
Dim ShowTable As New OleDb.OleDbCommand
Dim RAD As OleDb.OleDbDataReader
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
ShowTable.Connection = Conn
ShowTable.CommandType = CommandType.Text
ShowTable.CommandText = "SELECT Sum(qty) AS [totqty] FROM moves WHERE [mat_id] = " & MT_TEXT.SelectedValue.ToString & ""
Conn.Open()
RAD = ShowTable.ExecuteReader()
While RAD.Read
SUM_TEXT.Text = RAD.GetDouble("totqty")
End While
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Try
Me.MovesTableAdapter.FillByMat(Me.RMMDS.moves, MT_TEXT.SelectedValue)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
When I run the application and select the material from "MT_TEXT" combobox and then click on the button the data grid view is filled greatly with all material moves. but the SUM_TEXT text box is still empty. and get the error message "Conversion From string "totqty" to integer is not valid"
Please is there any solution for this problem
SELECT Sum(qty) AS totqty FROM...? Also, I recommend using SQL parameters instead of concatentating the query value into the SQL string.