Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

View record in textboxes

Below is the code I'm using...

User enters a slip_number, clicks find, I fill data adapter and try to display.  I must be missing something...

Private Sub View_Slip()


        Dim Slip_Info_SQL As String = "SELECT * FROM Slip_Info WHERE Slip_Number = '" & Me.txt_Slip_Number.Text & "'"
        Dim DA_Slip_Info As New SqlDataAdapter(Slip_Info_SQL, My.Settings.IEC_DB_Connection)
        Dim ds_Slip_Info As New DataSet

        DA_Slip_Info.Fill(ds_Slip_Info, "Slip_Info")

        If ds_Slip_Info.Tables("Slip_Info").Rows.Count = 1 Then
            Try
                Me.txt_Slip_Number.Text = ds_Slip_Info.Tables("Slip_Info").Rows(0).Item("Slip_Number")
                Me.DatePick_Slip_Date.Value = ds_Slip_Info.Tables("Slip_Info").Rows(0).Item("Slip_Date")
                Me.txt_Location.Text = ds_Slip_Info.Tables("Slip_Info").Rows(0).Item("Location")
                Me.txt_Job_Number.Text = ds_Slip_Info.Tables("Slip_Info").Rows(0).Item("Job_Number")
                Me.txt_Engineer.Text = ds_Slip_Info.Tables("Slip_Info").Rows(0).Item("Engineer")
                Me.txt_contractor.Text = ds_Slip_Info.Tables("Slip_Info").Rows(0).Item("Contractor")
                Me.txt_SWO_ID.Text = ds_Slip_Info.Tables("Slip_Info").Rows(0).Item("SWO_ID")
                Me.txt_Description.Text = ds_Slip_Info.Tables("Slip_Info").Rows(0).Item("Description")
            Catch ex As Exception
                Throw ex
            End Try
        End If


        ds_Slip_Info = Nothing


    End Sub
0
tobin46
Asked:
tobin46
  • 2
  • 2
  • 2
  • +1
2 Solutions
 
almanderCommented:
Is the SQL returning only one record, is Recordcount = 1?
0
 
EYoungCommented:
Change:
 If ds_Slip_Info.Tables("Slip_Info").Rows.Count = 1 Then

To:
 If ds_Slip_Info.Tables("Slip_Info").Rows.Count > 0 Then
0
 
tobin46Author Commented:
@almander - yes, there will only be one record returned as the "slip_number" is unique to the slip.

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
CodeCruiserCommented:
If you manually execute the query in sql management studio, does it work?
0
 
almanderCommented:
As CodeCruiser is eluding to. If the Result of the Query is not 1 record, the data will not be shown. The code looks like it will work. The only thing that I can see, is that the controls are never populated, because the RowCount is not 1.
0
 
tobin46Author Commented:
Query works fine...one record returned.  
0
 
CodeCruiserCommented:
Ok lets try another more suitable(for single record) approach



Private Sub View_Slip()


        Dim Slip_Info_SQL As String = "SELECT * FROM Slip_Info WHERE Slip_Number = '" & Me.txt_Slip_Number.Text & "'"
        Dim dbcon As New SqlConnection(My.Settings.IEC_DB_Connection)
        Dim dbcmd As New SqlCommand(Slip_Info_SQL, dbcon)
        dbcon.Open()
        Dim reader As SqlDataReader = dbcmd.ExecuteReader

        If reader.hasrows() Then
            Try
                reader.read()
                Me.txt_Slip_Number.Text = reader.Item("Slip_Number")
                Me.DatePick_Slip_Date.Value = reader.Item("Slip_Date")
                Me.txt_Location.Text = reader.Item("Location")
                Me.txt_Job_Number.Text = reader.Item("Job_Number")
                Me.txt_Engineer.Text = reader.Item("Engineer")
                Me.txt_contractor.Text = reader.Item("Contractor")
                Me.txt_SWO_ID.Text = reader.Item("SWO_ID")
                Me.txt_Description.Text = reader.Item("Description")
            Catch ex As Exception
                msgbox ex.Message
            End Try
        Else
            msgbox "No Record!"
        End If


        ds_Slip_Info = Nothing


    End Sub

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now