Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL and GridView
    text
    copied!<p>I am currently doing a project on web service for wine. I have the wine table with wineName and wineType. Also I have the search function implemented in the webservice coding as well as a separate webform to call the function of the search function</p> <p>I have the following code for performing search in the search service:</p> <pre><code>&lt;WebMethod()&gt; _ Public Function Search(ByVal searchName As String) As System.Data.DataSet Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString Dim con As New SqlConnection(connectionString) Dim selectSql As String = "SELECT * From Wine WHERE WineType='" &amp; searchName + "'" Dim selectAdapter As New Data.SqlClient.SqlDataAdapter(selectSql, con) Dim ds As New Data.DataSet con.Open() selectAdapter.Fill(ds, "Wine") con.Close() Return ds End Function </code></pre> <p>As for the webform, it's just a simple page with textbox labeled as searchName, a button and a gridView1 tied to ObjectDataSource.</p> <p>This is the coding i have for webform:</p> <pre><code>Partial Class Search Inherits System.Web.UI.Page Dim searching As searchwine.Service = New searchwine.Service Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click If searchName.Text = "" Then lblDisplayError.Text = "Can't search empty field!" Else Dim ds As DataSet = searching.Search(searchName.Text) GridView1.DataSource = ds.Tables(0) GridView1.DataBind() GridView1.Visible = True lblDisplayError.Visible = False End If End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load lblDisplayError.Text = "" GridView1.Visible = False End Sub End Class </code></pre> <p>Everything seems fine, but i have the following error when i want to do a search:</p> <blockquote> <p>System.NullReferenceException: Object reference not set to an instance of an object. at Service.Search(String searchName)</p> </blockquote> <p>Can anyone help me out please?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload