title: Check if Column Value Exists in Dataset using C# and ASP
body: <p>I've tried various solutions I have found and either I don't know how to implement them properly or they simply won't work. I have a method that allows someone to search a table for a specific order number, then the rest of the row will display in a gridview. However, if an order number is entered that doesn't exist in the table then I can get server error/exception. How can I make it so that before the search goes through or while the search goes through, if an order number that does't exist in the database is searched for then I can create the error instead?</p>
  
  <p>I am using an ms access database, C#, and ASP. </p>
  
  <p>Here is some of the code I am working with: </p>
  
  <p>the method for searching the order table: </p>
  
  <pre><code>public static dsOrder SearchOrder(string database, string orderNum)
  {
      dsOrder DS;
      OleDbConnection sqlConn;
      OleDbDataAdapter sqlDA;
  
      sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + database);
  
      DS = new dsOrder();
  
      sqlDA = new OleDbDataAdapter("select * from [Order] where order_num='" + orderNum + "'" , sqlConn);
  
      sqlDA.Fill(DS.Order);
  
      return DS;
  }
  </code></pre>
  
  <p>And using that method:</p>
  
  <pre><code>protected void btnSearch_Click(object sender, EventArgs e)
  {
      Session["OrderNum"] = txtSearch.Text;
      Session["ddl"] = ddlSearch.Text;
  
  
      if (Session["ddl"].ToString() == "Order")
      {
          dsOrder dataSet2;
  
          dataSet2 = Operations.SearchOrder(Server.MapPath("wsc_database.accdb"), Session["OrderNum"].ToString());
  
          grdSearch.DataSource = dataSet2.Tables["Order"];
  
          grdSearch.DataBind();
  
      }
  </code></pre>
  
  <p>Do I need to do a try/catch?</p>
  
  <p>A huge thanks in advance to who is able to help me!</p>