Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 2nd, 2013  |  syntax: None  |  size: 1.57 KB  |  views: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. else if (combo_View.Text == "Orders")
  2. {
  3.  
  4.     da.SelectCommand = new OleDbCommand("SELECT * FROM TestQuery WHERE (VendorName = @VendorName OR @VendorName = '') AND (CustomerName = @CustomerName OR @CustomerName = '') AND (PO = @PO OR @PO = '')  AND (ItemNum = @ItemNum OR @ItemNum = '') AND (orderDate BETWEEN @From AND @To) ORDER BY CustomerName", cs);
  5.  
  6.     //da.SelectCommand = new OleDbCommand("SELECT * FROM TestQuery WHERE orderDate BETWEEN @From AND @To", cs);
  7.  
  8.     da.SelectCommand.Parameters.Add("@VendorName", OleDbType.VarChar).Value = combo_VendorView.Text.ToString();
  9.     da.SelectCommand.Parameters.Add("@CustomerName", OleDbType.VarChar).Value = combo_CustomerView.Text.ToString();
  10.  
  11.     da.SelectCommand.Parameters.Add("@From", OleDbType.Date).Value = "#" + tp_viewFrom.Value.Date.ToString("M/d/yyyy") + "#";
  12.     da.SelectCommand.Parameters.Add("@To", OleDbType.Date).Value = "#" + tp_viewTo.Value.Date.ToString("M/d/yyyy") + "#";
  13.  
  14.     da.SelectCommand.Parameters.Add("@PO", OleDbType.VarChar).Value = txt_POLookup.Text.ToString();
  15.     da.SelectCommand.Parameters.Add("@ItemNum", OleDbType.VarChar).Value = combo_ItemNumLookup.Text.ToString();
  16.  
  17.  
  18.     dsB.Clear();
  19.     da.Fill(dsB);
  20.     dgv_DataLookup.DataSource = dsB.Tables[0];
  21. }
  22.        
  23. da.SelectCommand = new OleDbCommand("SELECT * FROM TestQuery WHERE
  24.     (VendorName = @VendorName OR @VendorName = '')
  25.     AND (CustomerName = @CustomerName OR @CustomerName = '')
  26.     AND orderDate BETWEEN @From AND @To ORDER BY CustomerName", cs);
  27.        
  28. and (@from is null or @to is null or <between stmt> )
  29.        
  30. VendorName = @VendorName OR @VendorName = ''