I have seen the question posed on this link but it doesn't solve my problem
This is my code:
Private Sub BindGrid()
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim query As String = "SELECT ContactName,REF,BRANCH,AMT_ON FROM dbo.dispatchedbranches where ref=@ref or @ref=''"
Dim cmd As New sqlcommand(query)
cmd.Parameters.AddWithValue("@ref", TextBox1.Text)
Using con As New SqlConnection(conString)
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using ds As New DataSet()
sda.Fill(ds)
gvCustomers.DataSource = ds
gvCustomers.DataBind()
End Using
End Using
End Using
End Sub
End Class
; I tried this solution but it is not working : see link to a probable solution NullReferenceExecption was unhandled by User code error while connecting Sql Local db using vb.net in visual studio 2013