title: How to search SQL database and display in C# listview
body: <p>I need to filter an SQL database using C# to display it in a windowsFormsHost.</p>
  
  <p>For that, I created a text box in which you input the required string. Using this input, the code uses the text to search through the database and display on clicking a refresh button.</p>
  
  <p>The refresh button works and is done, I just need to create the list with the selected rows according to my filter.</p>
  
  <p>Here is the code, which states that no value is returned:</p>
  
  <pre><code>    private string GetPassengerList(string sPasssenger)
      {
      string sPasssengerL = textBoxPassengerName.Text;
          if (sPasssenger.Trim().Length &gt; 0)
          {
              string sToTime = dtpToDate.Value.Year.ToString("D4") + @"/" + dtpToDate.Value.Month.ToString("D2") + @"/" + dtpToDate.Value.Day.ToString("D2");
              sToTime += @" " + dtpToTime.Value.Hour.ToString("D2") + @":" + dtpToTime.Value.Minute.ToString("D2") + @":" + dtpToTime.Value.Second.ToString("D2");
              string sFromTime = dtpFromDate.Value.Year.ToString("D4") + @"/" + dtpFromDate.Value.Month.ToString("D2") + @"/" + dtpFromDate.Value.Day.ToString("D2");
              sFromTime += @" " + dtpFromTime.Value.Hour.ToString("D2") + @":" + dtpFromTime.Value.Minute.ToString("D2") + @":" + dtpFromTime.Value.Second.ToString("D2");
  
              string sSqlSelect = @"SELECT Passenger FROM ";
              string sSqlWhere = @" WHERE (Created BETWEEN '" + sFromTime + @"' AND '" + sToTime + @"')";// and (IATA='" + sIata + @"')";
              string sSqlLike = @" LIKE '%" + sPasssengerL + "'%";
  
              SqlDataReader sqlReader = null;
              try {
                  SqlCommand sqlCommand = new SqlCommand(sSqlSelect + @"dbo.BagData" + sSqlWhere + sSqlLike, this.dbConnection);
                  sqlReader = sqlCommand.ExecuteReader();
                  if(!sqlReader.Read()) {
                      sqlReader.Close();
                      sqlCommand.CommandText = sSqlSelect + @"dbo.BagDataHistory" + sSqlWhere + sSqlLike;
                      sqlReader = sqlCommand.ExecuteReader();
                      if(!sqlReader.Read()) {
                          sqlReader.Close();
                          sqlCommand.CommandText = sSqlSelect + @"dbo.BagDataArchive" + sSqlWhere + sSqlLike;
                          sqlReader = sqlCommand.ExecuteReader();
                          if(!sqlReader.Read()) {
                                  sqlReader.Close();
                          }
                      }
                  }
                  if(!sqlReader.IsClosed) {
                      sPasssengerL = this.GetSqlDataString(@"Passenger", sqlReader);
                      sqlReader.Close();
                  }
              }
              catch(SqlException x) {
                  MessageBox.Show(@"GetPassengerName(): SQL Exception: " + x.Message, this.GetHashString("Error"), MessageBoxButton.OK, MessageBoxImage.Error);
              }
              catch(Exception ex) {
                  MessageBox.Show(@"GetPassengerName(): General Exception: " + ex.Message, this.GetHashString("Error"), MessageBoxButton.OK, MessageBoxImage.Error);
              }
              finally {
                  if(sqlReader != null) {
                      if(!sqlReader.IsClosed) {
                          sqlReader.Close();
                      }
                  }
              }
              return sPasssengerL;
          }
      }
  </code></pre>