I am converting a vb6 project to .net and half done. I am still trying to get a handle on Datasets and datareaders but so far so good. I have a form that when it loads does the following:
1. Loads a combobox with all userids (Done with dataset from one table)
2. Loads a listbox with all items that can be requested (done with a datareader from a second table)
3. Count the number of records in a third table and display the next number or the number 1 if no records (THE PROBLEM)

Here is the code so far (combo box code not here as it was done with the wizard)

VB Code:
  1. Private Sub Request_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
  2.         DsSN1.Clear()
  3.         SqlDataAdapter1.Fill(DsSN1)
  4.         Dim cn1 As New SqlConnection
  5.         Dim da1 As New SqlDataAdapter
  6.  
  7.         'Populate the listbox step 2
  8.         cn1.ConnectionString = "workstation id=""S-KG-CFSCE-2098"";packet size=4096;integrated security=SSPI;data s" & _
  9.         "ource=""KG-CFSCE-2B"";persist security info=False;initial catalog=TrainingManageme" & _
  10.         "ntDB"
  11.         cn1.Open()
  12.         Dim cmdtext As String = "Select distinct Asset, AssetConfig from Equipment where Type = 'Equipment' order by asset asc"
  13.         da1.SelectCommand = New SqlCommand(cmdtext, cn1)
  14.         Dim dr As SqlDataReader = da1.SelectCommand.ExecuteReader
  15.         While dr.Read
  16.             If dr.IsDBNull(0) Then
  17.                 List1.Items.Add((vbNullString & " " & dr.GetString(1)))
  18.             End If
  19.             If dr.IsDBNull(1) Then
  20.                 List1.Items.Add((dr.GetString(0) & " " & vbNullString))
  21.             Else
  22.                 List1.Items.Add((dr.GetString(0) & " " & dr.GetString(1)))
  23.             End If
  24.  
  25.         End While
  26.         dr.Close()
  27.         cn1.Close()
  28.         List1.SelectedIndex = 0
  29.  
  30.         ''Get Highest Request Number and add one step 3
  31.         cn1.ConnectionString = "workstation id=""S-KG-CFSCE-2098"";packet size=4096;integrated security=SSPI;data s" & _
  32.                 "ource=""KG-CFSCE-2B"";persist security info=False;initial catalog=TrainingManagementDB"
  33.         cn1.Open()
  34.         Dim cmdtext2 As String = "Select Count(RequestNum) from Request"
  35.         da1.SelectCommand = New SqlCommand(cmdtext2, cn1)
  36.         Dim dr2 As SqlDataReader = da1.SelectCommand.ExecuteReader
  37.         While dr2.Read
  38.             If dr2.IsDBNull(0) Then
  39.                 txtNum.text = 1
  40.             Else
  41.                 txtNum.text =(Cint(dr.GetString(0)) +1)
  42.             End If
  43.         End While
  44.  
  45.  
  46.     End Sub