Fixing the
SQL Injection[
^] vulnerability in your code will most likely solve the error message as well:
Private Sub viewrptrs_Click(sender As System.Object, e As System.EventArgs) Handles viewrptrs.Click
Using con As New SqlConnection("Data Source=ASHUTOSH-PC\SQLEXPRESS;Initial Catalog=Art Station Management System;Integrated Security=True")
Using com As New SqlCommand("Select sstudentid, sname, smiddlename, ssurname, ccoursename from StudentRegister WHERE sdatereg BETWEEN @datefrom AND @dateto", con)
com.Parameters.AddWithValue("@datefrom", DateTimePicker1.Value.Date)
com.Parameters.AddWithValue("@dateto", DateTimePicker2.Value.Date)
Using da As New SqlDataAdapter(com)
Dim ds As New DataSet()
da.Fill(ds, "StudentRegister")
DataGridView1.DataSource = ds.Tables(0)
End Using
End Using
End Using
End Sub
While you're at it, do yourself a favour and give your controls meaningful names. You might remember that
TextBox42
holds the "frood name"
today; but when you come back to your code in six months, you'll be struggling.