|
-
Jun 4th, 2005, 06:24 PM
#1
Thread Starter
Fanatic Member
Long SQL statements
VB Code:
Private Sub SetSQLStatements()
'Add parameters to use in SQL statements
With cmdStaff.Parameters
.Add("@EmpID", txtEmpID.Text)
.Add("@Surname", txtSurname.Text)
.Add("@Forename", txtForename.Text)
.Add("@Gender", txtGender.Text)
.Add("@DOB", dtpDOB.Text)
.Add("@Address", txtAddress.Text)
.Add("@Postcode", txtPostcode.Text)
.Add("@TelNum", txtTelNum.Text)
.Add("@Contract", txtContract.Text)
.Add("@Salary", txtSalary.Text)
.Add("@Position", txtPosition.Text)
.Add("@StartDate", dtpStartDate.Text)
.Add("@BookRight", cboBookingRights.Text)
.Add("@LoginRight", cboLoginRights.Text)
.Add("@MemberRight", cboMemberRights.Text)
.Add("@ManageRight", cboManageRights.Text)
End With
'Set SQL statements
With daStaff
.DeleteCommand.CommandText = "DELETE FROM Staff" 'Delete statement
.InsertCommand.CommandText = "INSERT INTO Staff" 'Insert statement
.[B]UpdateCommand.CommandText = "UPDATE Staff SET Address = @Address, BookingRights = @BookRight, Contract = @Contract, DOB = @DOB, Forename = @Forename, Gender = @Gender, LoginRights = @LoginRight, ManageRights = @ManageRight, MemberRights = @MemberRight, Position = @Position, Postcode = @Postcode, Salary = @Salary, StartDate = @StartDate, Surname = @Surname, [Telephone Number] = @TelNum" 'Update statement[/B]
End With
End Sub
What can i do make the SQL statement in bold stretch over more lines of code, so that the whole statement can be seen without scrolling the code window?
When i try to do this like i would with an ordinary string i get a syntax error.
p.s. I take a string to a new line by doing.
VB Code:
Dim bla as String
bla = "bla......................................................................." & _
"hello"
This doesn't appear to work with SQL statements though.
Last edited by x-ice; Jun 4th, 2005 at 06:31 PM.
-
Jun 4th, 2005, 06:29 PM
#2
Thread Starter
Fanatic Member
Re: Long SQL statements
I did a little messing around, here is the solution.
VB Code:
Dim SQLUpdateStr As String
'SQL Update string
SQLUpdateStr = "UPDATE Staff SET Address = @Address, BookingRights = @BookRight," & _
"Contract = @Contract, DOB = @DOB, Forename = @Forename, Gender = @Gender," & _
"LoginRights = @LoginRight, ManageRights = @ManageRight, MemberRights = @MemberRight," & _
"Position = @Position, Postcode = @Postcode, Salary = @Salary, StartDate = @StartDate," & _
"Surname = @Surname, [Telephone Number] = @TelNum"
'Set SQL statements
With daStaff
.DeleteCommand.CommandText = "DELETE FROM Staff" 'Delete statement
.InsertCommand.CommandText = "INSERT INTO Staff" 'Insert statement
.UpdateCommand.CommandText = SQLUpdateStr 'Update statement
End With
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|