因为如下所示,我的' sql'字符串太长了,我该如何组织这个插入字符串? 谢谢!
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
答案 0 :(得分:0)
以下是您可以遵循的一些简单步骤,以实现您的需求......
这不会让它变得更小但更有条理。
这是一个简单的例子......
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
然后你可以这样使用它......
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