I have the following code: -
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startpayrollButton.Click
-
Dim ssql As String = "select MAX(payrolldate) AS [payrolldate], " & _
-
"dateadd(dd, ((datediff(dd, '17530107', MAX(payrolldate))/7)*7)+7, '17530107') AS [Sunday]" & _
-
"from dbo.payroll" & _
-
" where payrollran = 'no'"
-
Dim oCmd As System.Data.SqlClient.SqlCommand
-
Dim oDr As System.Data.SqlClient.SqlDataReader
-
-
oCmd = New System.Data.SqlClient.SqlCommand
-
Try
-
With oCmd
-
.Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx)
-
.Connection.Open()
-
.CommandType = CommandType.Text
-
.CommandText = ssql
-
oDr = .ExecuteReader()
-
End With
-
If oDr.Read Then
-
payPeriodStartDate = oDr.GetDateTime(1)
-
payPeriodEndDate = payPeriodStartDate.AddDays(7)
-
Dim ButtonDialogResult As DialogResult
-
ButtonDialogResult = MessageBox.Show(" The Next Payroll Start Date is: " & payPeriodStartDate.ToString() & System.Environment.NewLine & " Through End Date: " & payPeriodEndDate.ToString())
-
If ButtonDialogResult = Windows.Forms.DialogResult.OK Then
-
-
exceptionsButton.Enabled = True
-
startpayrollButton.Enabled = False
-
-
End If
-
End If
-
oDr.Close()
-
oCmd.Connection.Close()
-
Catch ex As Exception
-
MessageBox.Show(ex.Message)
-
oCmd.Connection.Close()
-
End Try
-
-
End Sub
-
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exceptionsButton.Click
-
Dim sql As String = "SELECT [Exceptions].Employeenumber,[Exceptions].exceptiondate, [Exceptions].starttime, [exceptions].endtime, [Exceptions].code, datediff(minute, starttime, endtime) as duration INTO scratchpad3" & _
-
"FROM Employees INNER JOIN Exceptions ON [Exceptions].EmployeeNumber = [Exceptions].Employeenumber" & _
-
"where [Exceptions].exceptiondate between @payperiodstartdate and @payperiodenddate" & _
-
"GROUP BY [Exceptions].Employeenumber, [Exceptions].Exceptiondate, [Exceptions].starttime, [exceptions].endtime," & _
-
"[Exceptions].code, [Exceptions].exceptiondate"
-
Dim oCmd As System.Data.SqlClient.SqlCommand
-
Dim oDr As System.Data.SqlClient.SqlDataReader
-
oCmd = New System.Data.SqlClient.SqlCommand
-
Dim myCommand As New SqlClient.SqlCommand()
-
Try
-
With oCmd
-
.Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
-
.Connection.Open()
-
.CommandType = CommandType.Text
-
.CommandText = sql
-
oDr = .ExecuteReader()
-
myCommand.Parameters.AddWithValue("@payperiodstartdate", payPeriodStartDate)
-
myCommand.Parameters.AddWithValue("@payperiodenddate", payPeriodEndDate)
-
myCommand.CommandText = "dbo.sp_opsum"
-
End With
-
oDr.Close()
-
oCmd.Connection.Close()
-
Catch ex As Exception
-
MessageBox.Show(ex.Message)
-
oCmd.Connection.Close()
-
End Try
-
Exceptions.Show()
-
End Sub
-
and when I run the program I get the error:
"Line1: Incorrect syntax near 'Employees'"
Which is part of my second SQL query. I can debug up to that point without my application breaking. I have gone back to my SQL management studio and ran (and re-ran) my sql query and it works fine. Can someone please help me as to why when I run a working query in VB, it throws this error?
Thank you
Doug
6 3506
take a look at your INNER JOIN. you have - INNER JOIN Exceptions ON [Exceptions].EmployeeNumber = [Exceptions].Employeenumber
you may want to correct this. But I think your issue is what Rabbit is saying...
Rabbit 12,516
Recognized Expert Moderator MVP - strVar = "Hello" & _
-
"World"
The results is HelloWorld.
Rabbit,
So then how I have my query formatted is incorrect?
is this any clearer? - strVar = "Hi" & _
-
"my" & _
-
"name" & _
-
"is" & _
-
"slim" & _
-
"shady" & _
The results is Himynameisslims hady
Rabbit 12,516
Recognized Expert Moderator MVP
Yes, put a space at the end or beginning of the lines. - strVar = "Hello" & _
-
" World"
Result is "Hello World"
Thanks,
that's what it was.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mark Findlay |
last post by:
Hello Experts!
I am attempting to use the OleDbCommand.ExecuteScaler() function within my
ASP.NET C# web page to perform a simple validation, but receive the
following error:
"Incorrect syntax near the keyword 'DEFAULT'"
The form has 2 fields on it, called tb_username and tb_password. (see code
snippet below).
|
by: martin1 |
last post by:
I just use DataSet to bind DataSetGrid and display from SQL DB.
when starting run in Visual Studio 2005, get "Line 1: Incorrect syntax near
'1'" error message from below fill line,
objDataAdapter.Fill(objDataSet, "mindata")
any help is greatly appriciated.
|
by: netone |
last post by:
I am developing site using dot NET....
when I use this sql query
Dim mydata As String = "SELECT director.applno, district.distName, disabappl.recvddate_sdo, disabappissue.IDCardNo, director.dreceived_director" _
& " FROM director INNER JOIN disabappl ON director.applno = disabappl.applno INNER JOIN " _
& " district ON disabappl.submitted_dist = district.dist_cd INNER JOIN" _
&...
|
by: iporter |
last post by:
In the following code, the two Response.Write statements output exactly
the same - I can copy and paste both into Query Analyzer, and run them
fine. However, if I comment out line 3, the assignment of "SELECT
T..." to the variable query, the last line produces the error:
Line 1: Incorrect syntax near '<'.
Many thanks in advance for any explanation - the problem is tearing my
hair out!!
Iain
|
by: wallic |
last post by:
Hello,
This is my first post and I am a beginner with SQL code. The code below is supposed to update a new table (loctable) with a calculated value based on the original table (hra_data). There are 3 possibilities in the hra_data table that will cause the loctable to be updated with the calculated value. After playing with it, I thought it was in the correct format but I keep getting an "Incorrect syntax..." error. Any guidence would be...
| |
by: roamnet |
last post by:
hi
i created database file with .mdf extention ,sql server as a source
and use grid view to display data
there're no problem in data retrieve and display,but i want to edit it
or insert new records
there is an error "Incorrect syntax near '-'.
Must declare the scalar variable "@UserName".
I worked out in design view,code is automatically generated.Iam not
able fix the error.
Iam working with Visual Web Developer-2005 Express Edition
|
by: Chris Kennedy |
last post by:
Hi all
I'm running SQL Server 2005 Express Edition.
One database
One table called Sites
Fields as follows:
id (bigint, Identity, Primary Key)
SiteName (varchar(50), allows nulls)
Generation (float)
LastUpdated (varchar(50), allows nulls)
|
by: mahendra dubey |
last post by:
I have SQl Server 2005 SP1.I am running following query
ALTER USER WITH LOGIN =
I have created both user and login with name myuser.
but this query returns error
Msg 102, Level 15, State 1, Server ..., Line 1
Incorrect syntax near 'LOGIN'.
Same query can be run on SQL server 2005 SP3,SQL Server 2008...
|
by: NeoPa |
last post by:
As the title implies, I am getting the following error message with some SQL I'm trying to use. I'm using MS Management Studio 2008 with a link to a 2005 server.
What confuses me is that when I change the first line from a DELETE to a SELECT, the SQL works exactly as I would expect it to.
DELETE
FROM .. AS INNER JOIN
.. AS
ON SUBSTRING(.,2,3)=SUBSTRING(.,2,3)
AND .=.
WHERE SUBSTRING(.,1,1)='1'
GO
|
by: santhanalakshmi |
last post by:
Hi,
I am working on SQL 2008 database. In Micosoft SQL server Management studio, i am trying to insert multiple records at a time in a table, using this query
insert into test1 values(6,'san6',1),( 7,'san7',1);
Error:
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ','.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |