title: Null parameter not working with Access and OLE
body: <p>My understanding is to pass a null via ole parameter you use dbnull.value.</p>
  
  <p>This is my code</p>
  
  <pre><code>// Add user control to panel
  pcMaster.Controls.Add(new ucIndexCodes(DBNull.Value, DBNull.Value));
  </code></pre>
  
  <p>The ucIndexCodes control has this in the </p>
  
  <pre><code>public ucIndexCodes(object CustomerID, object ProjectID)
  {
      InitializeComponent();
      try
      {
          // Build parameters
          Queue&lt;OleDbParameter&gt; myParameters = new Queue&lt;OleDbParameter&gt;();
  
          myParameters.Enqueue(new OleDbParameter("@CustomerID", CustomerID));
          myParameters.Enqueue(new OleDbParameter("@ProjectID", ProjectID));
  
          // Build SQL statement
          string mySQL = "SELECT IndexCodeID, Attitude, Description, recursiveIndexCodeID, CustomerID, ProjectID FROM tblIndexCodes WHERE CustomerID = @CustomerID AND ProjectID = @ProjectID";
          // Get Data
          using (DataTable tblTopIndexCodes = Classes.clsDatabase.GetData(mySQL, myParameters))
          {
              if (tblTopIndexCodes != null)
              {
                  foreach (DataRow tmpRow in tblTopIndexCodes.Rows)
                  {
                      // Add Root node
                      TreeListNode objRoot = tlIndexCodes.Nodes.Add(new object[] { tmpRow["Attitude"], tmpRow["Description"].ToString() });
                      // Add child node of root
                      AddChildNode(objRoot, Convert.ToInt16(tmpRow["IndexCodeID"]));
                  }
              }
          }
      }
      catch (Exception ex)
      {
          ErrorHandle(ex);
      }
  }
  </code></pre>
  
  <p>The problem is that GetData returns a empty table, so there isn't any rows which means that it ran correctly just didn't return anything.</p>
  
  <pre><code>internal static DataTable GetData(string mySQL, Queue&lt;OleDbParameter&gt; myParameters = null)
  {
      // Data set to return
      DataTable myTable = new DataTable();
      try
      {
          using (OleDbConnection myConn = new OleDbConnection())
          {
              // Open connection to database
              myConn.ConnectionString = getStringConnection();
              myConn.Open();
  
              // Build SQL command
              using (OleDbCommand myCMD = new OleDbCommand())
              {
                  myCMD.CommandText = mySQL;
                  myCMD.CommandTimeout = 15000;
                  myCMD.CommandType = System.Data.CommandType.Text;
                  myCMD.Connection = myConn;
                  // Add parameters
                  if (myParameters != null)
                  {
                      foreach (OleDbParameter myParameter in myParameters)
                      {
                          myCMD.Parameters.Add(myParameter);
                      }
                  }
  
                  using (OleDbDataAdapter myData = new OleDbDataAdapter())
                  {
                      myData.SelectCommand = myCMD;
                      myData.Fill(myTable);
                  }
              }
          }
      }
      catch (Exception ex)
      {
          Console.Write(ex.Message.ToString());
          myTable = null;
      }
      return myTable;
  }
  </code></pre>
  
  <p>When I run this SQL in Access, it returns the expected data.  </p>
  
  <pre><code>SELECT IndexCodeID, Attitude, Description, recursiveIndexCodeID, CustomerID, ProjectID FROM tblIndexCodes WHERE CustomerID Is Null AND ProjectID Is Null
  </code></pre>
  
  <p>CustomerID and/or ProjectID may not always be null so I need the equal signal for queries like these.</p>
  
  <pre><code>SELECT IndexCodeID, Attitude, Description, recursiveIndexCodeID, CustomerID, ProjectID FROM tblIndexCodes WHERE CustomerID = 1 AND ProjectID = 1
  
  SELECT IndexCodeID, Attitude, Description, recursiveIndexCodeID, CustomerID, ProjectID FROM tblIndexCodes WHERE CustomerID = 1 AND ProjectID = Null
  </code></pre>
  
  <p>I can't find a solution to this.  I made sure CustomerID and ProjectID are in fact null by setting the default to null and also updating the customerid and projectid to null just for testing.</p>
  
  <p>Thanks for the help,
  Jim</p>