Question

since as you see below, my 'sql' string is just too long, how can i organize this insert string? thank you!

Try
        conn.Open()
        sql = "SELECT * FROM guests WHERE folio='" & folionum_txtfield.Text & "' AND fname = '" & Fname_txtfield.Text & "'"
        Dim sqlCom As New System.Data.OleDb.OleDbCommand(sql, conn)
        Dim sqlRead As System.Data.OleDb.OleDbDataReader = sqlCom.ExecuteReader()

        If Not sqlRead.HasRows Then
            sql = "INSERT INTO guests values (" & folionum & "," & lname & "," & fname & "," & address & "," & lname & "," & country & "," & company & "," & idtype & "," & otherID & "," & idtype & "," & otherID & "," & idnum & "," & otherID & "," & vehicle & "," & vmodel & "," & pnum & "," & rooomnum & "," & datechckin & "," & datechckout & "," & rmtype & numdays & "," & numadults & "," & numchild & "," & notes)
        End If

    Catch ex As Exception
Was it helpful?

Solution

Here's some simple steps you can follow to acheive what you would need...

  1. Create a DataClass for ex: GuestDataClass
  2. List some properties (setters & getters).
  3. Create a new instance of this class and set your properties.
  4. Create a function and pass the new instance to your function.
  5. Then you can use your properties to save or update etc... as needed.

This won't make it much smaller but more organized.

Here is a simple example...

 Public Class GuestDataClass 'This would be your new class for your properties...

 #Region "Variables" 'Add your variables here'
   Private strFirstName As String = String.Empty
   Private strLastName As String = String.Empty
 #End Region

 #Region "Properties" 'Add some properties'

 Public Property FirstName() As String
    Get
        Return strFirstName
    End Get
    Set(ByVal value As String)
        strFirstName = value
    End Set
 End Property

 Public Property LastName() As String
    Get
        Return strLastName
    End Get
    Set(ByVal value As String)
        strLastName = value
    End Set
 End Property

 #End Region

 #Region "Methods"

'Inserts new guest'
 Public Shared Function SaveGuest(ByVal oGuest As GuestDataClass) As Boolean

    'Use your properties for the save routine here... just an example...
    'oGuest.FirstName
    'oGuest.LastName 

    Return True
 End Function

 #End Region

 End Class

Then you can use this as such...

 Public Class Form1

 Private pData As GuestDataClass 'Set a variable in your class you can use..

 Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load

    'Set this variable of your data class...
    pData = New GuestDataClass()

    'Set our properties...
    pData.FirstName = "Bobby"
    pData.LastName = "Walters"

    'Save the data...
    If GuestDataClass.SaveGuest(pData) Then
        MessageBox.Show("Saved!")
    Else
        MessageBox.Show("Error!")
    End If


End Sub
End Class
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top