Question : Getting data from Access table

Hello,

I just don't see what is missing in this code - I keep getting this error:
 No value given for one or more required parameters.
I want to get the value ( a number) in the  field StudentsTotal. The field is in a table called Surveys in database called Survey.


 Dim Total As Integer
        Dim con As OleDbConnection
        Dim comm As OleDbCommand
        Dim reader As OleDbDataReader
        con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Survey.accdb;")
        comm = New OleDbCommand("Select studentsTotal from Surveys where surveyName= '" & Me.SurveyName.Text & "'", con)
        con.Open()
        reader = comm.ExecuteReader
        While reader.Read
            Total = reader.Item("studentsTotal")

        End While
        con.Close()

Answer : Getting data from Access table

did you try use parameters instead of put directly  Me.SurveyName.Text ......?
try this
 dim str as string= Me.SurveyName.Text    (or integer or whatever)
 comm = New OleDbCommand("Select studentsTotal from Surveys where surveyName= ?", con)
 comm.Parameters.AddWithValue("?",str)        or  comm.Parameters.AddWithValue("surveyName",str)
Random Solutions  
 
programming4us programming4us