Hi all,

I am populating a ComboBox using an SPROC using a SqlDataReader and it works perfectly; however, I want to be able to manually add a blank row to the SqlDataReader, so that the default option in the ComboBox is empty.

I can do this using a DataSet with no issues, but I don't want to update a database (MSSQL), I just want to pull information from the database to provide options to the end user.

This is what I have and how I am going about it. Any suggestions as to how this can be done? I have searched for many hours on adding a blank row to a SqlDataReader and have not found anything so far.

VB Code:
  1. ALTER PROCEDURE GetFeeFrequencies
  2. AS
  3. BEGIN
  4.     SELECT ServiceFeeFrequency AS SFF
  5.     FROM FeeFrequencies
  6.     ORDER BY SFF ASC
  7. END

VB Code:
  1. Private Sub CCProcessors_Load(ByVal sender As System.Object, _
  2.                                   ByVal e As System.EventArgs) Handles MyBase.Load
  3.  
  4.         LoadFeeFreqDropDown(ServiceFeeFrequencySR)
  5.     End Sub
  6.  
  7.     Public Sub LoadFeeFreqDropDown(ByVal CBName As Elegant.Ui.ComboBox)
  8.         Using SetDatabaseConnection As New SqlConnection(ConnectToDatabase)
  9.             Using GetFeeFreq As SqlCommand = New SqlCommand
  10.                 Try
  11.                     SetDatabaseConnection.Open()
  12.  
  13.                     With GetFeeFreq
  14.                         .Connection = SetDatabaseConnection
  15.                         .CommandType = CommandType.StoredProcedure
  16.                         .CommandText = "GetFeeFrequencies"
  17.                         .ExecuteNonQuery()
  18.                     End With
  19.  
  20.                     Dim FeeFreqDr As SqlDataReader
  21.                     FeeFreqDr = GetFeeFreq.ExecuteReader
  22.  
  23.                     'TODO: Add a blank entry/row to the SqlDataReader and make it default.
  24.  
  25.                     With CBName
  26.                         While FeeFreqDr.Read
  27.                             If FeeFreqDr.HasRows Then
  28.                                 .AutoCompleteMode = AutoCompleteMode.SuggestAppend
  29.                                 .AutoCompleteSource = AutoCompleteSource.ListItems
  30.                                 .Items.Add(FeeFreqDr("SFF"))
  31.                                 .DisplayMember = CStr(FeeFreqDr("SFF"))
  32.                                 .ValueMember = CStr(FeeFreqDr("SFF"))
  33.                                 '.Text = vbNullString
  34.                             End If
  35.                         End While
  36.                     End With
  37.  
  38.                     FeeFreqDr.Close()
  39.                 Catch CastEx As InvalidCastException
  40.                     MessageBox.Show(CastEx.ToString, _
  41.                                     "Invalid Cast Exception", _
  42.                                     MessageBoxButtons.OK, _
  43.                                     MessageBoxIcon.Error, _
  44.                                     MessageBoxDefaultButton.Button1)
  45.                 Catch ArgEx As ArgumentException
  46.                     MessageBox.Show(ArgEx.ToString, _
  47.                                     "Argument Exception", _
  48.                                     MessageBoxButtons.OK, _
  49.                                     MessageBoxIcon.Error, _
  50.                                     MessageBoxDefaultButton.Button1)
  51.                 Catch NullRefEx As NullReferenceException
  52.                     MessageBox.Show(NullRefEx.ToString, _
  53.                                     "Null Reference Exception", _
  54.                                     MessageBoxButtons.OK, _
  55.                                     MessageBoxIcon.Error, _
  56.                                     MessageBoxDefaultButton.Button1)
  57.                 Catch SQLEx As SqlException
  58.                     MessageBox.Show(SQLEx.ToString, _
  59.                                     "SQL Exception", _
  60.                                     MessageBoxButtons.OK, _
  61.                                     MessageBoxIcon.Error, _
  62.                                     MessageBoxDefaultButton.Button1)
  63.                 Catch FormatEx As FormatException
  64.                     MessageBox.Show(FormatEx.ToString, _
  65.                                     "Format Exception", _
  66.                                     MessageBoxButtons.OK, _
  67.                                     MessageBoxIcon.Error, _
  68.                                     MessageBoxDefaultButton.Button1)
  69.                 Catch OverflowEx As OverflowException
  70.                     MessageBox.Show(OverflowEx.ToString, _
  71.                                     "Overflow Exception", _
  72.                                     MessageBoxButtons.OK, _
  73.                                     MessageBoxIcon.Error, _
  74.                                     MessageBoxDefaultButton.Button1)
  75.                 Catch IdxOutOfRangeEx As IndexOutOfRangeException
  76.                     MessageBox.Show(IdxOutOfRangeEx.ToString, _
  77.                                     "Index Out Of Range Exception", _
  78.                                     MessageBoxButtons.OK, _
  79.                                     MessageBoxIcon.Error, _
  80.                                     MessageBoxDefaultButton.Button1)
  81.                 Finally
  82.                     SetDatabaseConnection.Close()
  83.                 End Try
  84.             End Using
  85.         End Using
  86.     End Sub