473,654 Members | 3,042 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting Syntax Error Converting from Character String

347 Contributor
I have the following code:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Public Class Main
  3.     Protected WithEvents DataGridView1 As DataGridView
  4.     Dim instForm2 As New Exceptions
  5.     Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startpayrollButton.Click
  6.         Dim ssql As String = "select MAX(payrolldate) AS [payrolldate], " & _
  7.                  "dateadd(s,  518399, max(payrolldate)) AS [Sunday]" & _
  8.                   "from dbo.payroll" & _
  9.                   " where payrollran = 'no'"
  10.         Dim oCmd As System.Data.SqlClient.SqlCommand
  11.         Dim oDr As System.Data.SqlClient.SqlDataReader
  12.         oCmd = New System.Data.SqlClient.SqlCommand
  13.  
  14.         Try
  15.             With oCmd
  16.                 .Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
  17.                 .Connection.Open()
  18.                 .CommandType = CommandType.Text
  19.                 .CommandText = ssql
  20.                 oDr = .ExecuteReader()
  21.             End With
  22.             If oDr.Read Then
  23.                 payperiodstartdate = oDr.GetDateTime(1)
  24.                 payperiodenddate = payperiodstartdate.AddDays(7)
  25.                 Dim ButtonDialogResult As DialogResult
  26.                 ButtonDialogResult = MessageBox.Show("      The Next Payroll Start Date is: " & payperiodstartdate.ToString() & System.Environment.NewLine & "            Through End Date: " & payperiodenddate.ToString())
  27.                 If ButtonDialogResult = Windows.Forms.DialogResult.OK Then
  28.                     exceptionsButton.Enabled = True
  29.                     startpayrollButton.Enabled = False
  30.                 End If
  31.             End If
  32.             oDr.Close()
  33.             oCmd.Connection.Close()
  34.         Catch ex As Exception
  35.             MessageBox.Show(ex.Message)
  36.             oCmd.Connection.Close()
  37.         End Try
  38.  
  39.     End Sub
  40.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exceptionsButton.Click
  41.         Dim connection As System.Data.SqlClient.SqlConnection
  42.         Dim adapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter
  43.         Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
  44.         Dim ds As New DataSet
  45.         Dim _sql As String = "SELECT [Exceptions].Employeenumber,[Exceptions].exceptiondate, [Exceptions].starttime, [exceptions].endtime, [Exceptions].code, datediff(minute, starttime, endtime)  as duration into Scratchpad3" & _
  46.         " FROM Employees INNER JOIN Exceptions ON [Exceptions].EmployeeNumber = [Exceptions].Employeenumber" & _
  47.          " where [Exceptions].exceptiondate between @payperiodstartdate and @payperiodenddate" & _
  48.          " GROUP BY [Exceptions].Employeenumber, [Exceptions].Exceptiondate, [Exceptions].starttime, [exceptions].endtime," & _
  49.          " [Exceptions].code, [Exceptions].exceptiondate"
  50.         connection = New SqlConnection(connectionString)
  51.         connection.Open()
  52.         Dim _CMD As SqlCommand = New SqlCommand(_sql, connection)
  53.         _CMD.Parameters.AddWithValue("@payperiodstartdate", payperiodstartdate)
  54.         _CMD.Parameters.AddWithValue("@payperiodenddate", payperiodenddate)
  55.         adapter.SelectCommand = _CMD
  56.         Try
  57.             adapter.Fill(ds)
  58.             If ds Is Nothing OrElse ds.Tables.Count = 0 OrElse ds.Tables(0).Rows.Count = 0 Then
  59.                 'it's empty
  60.                 MessageBox.Show("There was no data for this time period. Press Ok to continue", "No Data")
  61.                 connection.Close()
  62.                 Exceptions.saveButton.Enabled = False
  63.                 Exceptions.Hide()
  64.             Else
  65.                 connection.Close()
  66.             End If
  67.  
  68.         Catch ex As Exception
  69.             MessageBox.Show(ex.ToString)
  70.             connection.Close()
  71.         End Try
  72.         Exceptions.Show()
  73.     End Sub
  74.  
  75.     Private Sub payrollButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles payrollButton.Click
  76.         Payrollfinal.Show()
  77.     End Sub
  78. End Class
  79.  
and when I run this code, I get the following error
System.Data.SQL Client.SQLExcep tion: Syntax error converting from character string, line 57. Which is this line:

adapter.Fill(ds )

When I debug this, I put the line break on that line and look at the Table Value, which shows 0, but I know that there is data for that time frame. Can anyone please assist?
Jan 28 '11 #1
0 1425

Sign in to post your reply or Sign up for a free account.

Similar topics

1
38581
by: Justin Wong | last post by:
CREATE PROCEDURE dbo.Synchronization_GetNewRecords ( @item varchar(50), @last datetime ) AS SET NOCOUNT ON
2
7127
by: Anthony | last post by:
I have an inventory database that Im trying to create a report out of the IP address are a lookup on a seperat table but I keep getting the above error can I change the table row to something to fix this or what. SELECT i.INVENTORY_ITEM_ID AS ,i.HOST_NAME AS , '' AS Flag, i.MEMO AS Comments, 'Seattle' AS City, 'Washington' AS State, CASE WHEN fv.value = 'EL EET1410' THEN '1111 3rd Ave.' WHEN fv.value = 'EL WFL17' THEN '999 3rd Ave.'...
3
2661
by: kufre | last post by:
I need some fresh eyes to take a look at this code for me and let me know what it is I'm doing wrong because I keep getting all kinds of error message with this code. I've had several people help me with this code and every thing that've told me I've done but for the life of me I can't seem to get this working right. First I keep getting "Type mismatch" error message for this line of code: StrProject = Str(Me!cboProjectID) but if I take...
2
9286
by: Roy Rodsson via .NET 247 | last post by:
Hi all! I am using a stored procedure in SQL2000 for retrieving fileinformations from a db. the table as an uniqueidentifier for the file information. The stored procedure has a variable called fileIds that is oftype varchar. I am putting in a comma separated string with ids (such as:'9B176B0C-CA03-49C9-A2E7-063038E7CF20','9B176B0C-CA03-49C9-A2E7-063038E7CF22','9B176B0C-CA03-49C9-A2E7-063038E7CF23') However, when I execute the sp via...
1
1882
by: SealedClassSingleton | last post by:
Hi, When calling a stored procedure on a SQL 2005 DB with the managed SQL ADOprovider I got the following exception: Syntax error converting character string to uniqueidentifier when I use the following value for a unqiueidentifier variable {A00C9D36-CC20-475F-A285-777CC739199C}. If I use another random GUID the stored procedure executes fine. The value that gives problems, is a key that
1
2428
by: ronca | last post by:
Error Syntax error converting the varchar value $568.25 to a column of data type Statement I'm using Select Top 1000 * From mass.dbo.dbo_MASS where _amount > 5000 Want only row with _amount >5000 Help please
18
3774
by: rahuls | last post by:
Hi everyone, I have a couple of questions? 1.this is part of my main function ////////////////////////////// int main() { FILE *f1; int i,j; j=100000000; int intData;
1
1288
werks
by: werks | last post by:
Hello Every time i input the character ' and % in the textfield it generate an error in my query. The error: Syntax error in query expression 'Title LIKE '%' %%';'. My code: adoList.Open "SELECT * FROM qryOPAC WHERE Title LIKE '%" & varExp & "%';",CoNN,3,3
1
4668
by: SnehaAgrawal | last post by:
Hi I get the error "Syntax error converting datetime from character string "for the following sql statement in Stored proc. SET @dynamicSQL =N'SELECT CUSTID,SHCodeLink FROM AccountMaster where CONVERT(DATETIME,OPDATE,105) < = '''+CONVERT(DATETIME,@ACCYEAR,105) +''' And GLCode = '+@DIVGLCODE EXEC(@dynamicsql)
7
2841
by: Yesurbius | last post by:
I am receiving the following error when attempting to run my query. In my mind - this error should not be happening - its a straight-forward query with a subquery. I am using Access 2003 with all the latest patches. If I do not group the query (ie. remove aggregation) it will work. If I recall, it also works if my subquery does not have joins. I want to accomplish this with pure SQL .. I could easily write a VBA function to handle...
0
8375
marktang
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...
0
8815
Oralloy
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...
0
8707
jinu1996
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...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5622
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();...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2714
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
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.