473,804 Members | 3,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP and SQL driving me nuts

BezerkRogue
68 New Member
I have gotten my pages to work up to the final edit page. The code executes on load. Variables are passed by session but I get an SQL syntax error. I've tested the sp I'm calling and it works correctly. Here's the code"

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
Dim strSelDate
Dim strShift
Dim strAbsent
Dim strTO
Dim strHeadCount
Dim strSTDHeadCount
Dim strMPNotes
Dim Notes2
Dim strSQL
Dim strRID

strRID = Session.Item("R ID").ToString ()
strSelDate = Session.Item("S elDate").ToStri ng()
strShift = Session.Item("S hift").ToString ()
strAbsent = Session.Item("A bsent").ToStrin g()
strTO = Session.Item("T O").ToString ()
strHeadCount = Session.Item("H eadCount").ToSt ring()
strSTDHeadCount = Session.Item("S TDHeadCount").T oString()
strMPNotes = Session.Item("N otes").ToString ()
'Notes2 = strMPNotes.Repl ace("'", "''")
strSQL = "UP_MANPOWER_RE CORD_UPDATE '" & strSelDate & "', '" & strShift & "', " & strHeadCount & ", " & strSTDHeadCount & ", " & strAbsent & ", " & strTO & ", '" & Notes2 & "', " & strRID
Dim objConn As New Data.SqlClient. SqlConnection(" Data Source=XXXXXX;I nitial Catalog=XXXXXX; User ID=XXXXXX;passw ord=XXXXXX;")
Dim objCmd As New Data.SqlClient. SqlCommand(strS QL, objConn)
objConn.Open()
objCmd.ExecuteN onQuery()
objConn.Close()

End Sub

Here's the error I get:

System.Data.Sql Client.SqlExcep tion: Line 1: Incorrect syntax near '.'.

Can anyone enlighten this drowning noob??
Oct 24 '07
28 2179
BezerkRogue
68 New Member
hehe oops, my mistake, I didn't look at the variable name close enough to see it said it was Date.

If you set a breakpoint here:
Expand|Select|Wrap|Line Numbers
  1. Dim objConn As New Data.SqlClient.SqlConnection("Data Source=XXXXXX;Initial Catalog=XXXXXX;User ID=XXXXXX;password=XXXXXX;")
  2.  
what does the value of your sql query strSQL, look like? Maybe there's something that can be caught by seeing how it is displayed?
By the way, is that a stored procedure you're trying to run there?

Yeah. Here's the code for the SP:

ALTER PROCEDURE UP_MANPOWER_REC ORD_UPDATE
@Date datetime,
@Shift varchar(10),
@HeadCount int,
@STDHeadCount int,
@Absent int,
@TO int,
@Notes varchar(1000),
@RID int
AS
Update Manpower_Data
set Date = @Date, Shift_ID = (select shift_id from shift where shift=@Shift) , HeadCount = @HeadCount, STDHeadCount= @STDHeadCount, Absent= @Absent, [TO] = @TO, Notes= @Notes
where RID = @RID
Oct 25 '07 #11
Plater
7,872 Recognized Expert Expert
ah ha! That's why. I suspected it from the begining and shoulda listened to myself.

That's not how you call stored procedures in .NET.

Here is a (long) example taken directly from one of my projects.
dbcon is the name of my open dbconnection
"InsertNewBoard Assembly" is the name of my stored procedure. You can see how parameters are added, including the OUTPUT paramter.
Expand|Select|Wrap|Line Numbers
  1. Public Shared Function InsertNewBoardAssembly(ByVal Name As String, ByVal BoardAssemblyNumber As String, ByVal RevNumber As Integer, ByVal BOMID As Int64, ByVal PartID As Int64, ByVal Notes As String) As Int64 
  2.     Dim retval As Int64 = -1 
  3.     Dim logmsg As String = "" 
  4.  
  5.     Try 
  6.         Dim ModifiedDate As DateTime = DateTime.Now 
  7.         Dim sc As New SqlCommand("InsertNewBoardAssembly", dbcon) 
  8.         sc.CommandType = CommandType.StoredProcedure 
  9.  
  10.         sc.Parameters.Add("@Name", SqlDbType.VarChar) 
  11.         sc.Parameters("@Name").Value = quoteReplace(Name) 
  12.  
  13.         sc.Parameters.Add("@BoardAssemblyNumber", SqlDbType.VarChar) 
  14.         sc.Parameters("@BoardAssemblyNumber").Value = quoteReplace(BoardAssemblyNumber) 
  15.  
  16.         sc.Parameters.Add("@RevNumber", SqlDbType.Int) 
  17.         sc.Parameters("@RevNumber").Value = RevNumber 
  18.  
  19.         sc.Parameters.Add("@BOMID", SqlDbType.BigInt) 
  20.         sc.Parameters("@BOMID").Value = BOMID 
  21.  
  22.         sc.Parameters.Add("@PartID", SqlDbType.BigInt) 
  23.         sc.Parameters("@PartID").Value = PartID 
  24.  
  25.         sc.Parameters.Add("@Notes", SqlDbType.VarChar) 
  26.         sc.Parameters("@Notes").Value = quoteReplace(Notes) 
  27.  
  28.         sc.Parameters.Add("@ModifiedDate", SqlDbType.DateTime) 
  29.         sc.Parameters("@ModifiedDate").Value = ModifiedDate 
  30.  
  31.         'out 
  32.         sc.Parameters.Add("@BoardAssemblyID", SqlDbType.BigInt) 
  33.         sc.Parameters("@BoardAssemblyID").Direction = ParameterDirection.Output 
  34.         Dim numrows As Integer = sc.ExecuteNonQuery() 
  35.         retval = DirectCast(sc.Parameters("@BoardAssemblyID").Value, Int64) 
  36.         sc.Dispose() 
  37.     Catch ee As Exception 
  38.         ReportError("InsertNewBoardAssembly", ee) 
  39.     End Try 
  40.     Return retval 
  41. End Function 
  42.  
Oct 25 '07 #12
BezerkRogue
68 New Member
What does this error mean?

BC31029: Method 'Protected Sub Page_Load(sende r As Object, e As System.EventArg s, rDate As Date, Shift As String, HeadCount As Integer, STDHeadCount As Integer, Absent As Short, rTO As Integer, Notes As String, RID As Integer)' cannot handle Event 'Public Event Load(sender As Object, e As System.EventArg s)' because they do not have the same signature.
Oct 25 '07 #13
Plater
7,872 Recognized Expert Expert
Two of my field names are seen as keywords when I try to enter them in the args portion of the sub routine. How can I correct this. Renaming them in the DB won't work as the number of procedures and reports that read all of this is huge.
Enclose column names (and other database objects) with square brackets
[myTableName].[MyColumnName]=@Somevariable
Oct 25 '07 #14
BezerkRogue
68 New Member
Enclose column names (and other database objects) with square brackets
[myTableName].[MyColumnName]=@Somevariable
Ok. Here's what I have:

Dim objCmd As New Data.SqlClient. SqlCommand("UP_ MANPOWER_RECORD _UPDATE", objConn)
objCmd.CommandT ype = Data.CommandTyp e.StoredProcedu re

objCmd.Paramete rs.Add("@rDate" , Data.SqlDbType. DateTime)
objCmd.Paramete rs("@rDate").Va lue = strSelDate

objCmd.Paramete rs.Add("@Shift" , Data.SqlDbType. VarChar)
objCmd.Paramete rs("@Shift").Va lue = strShift

objCmd.Paramete rs.Add("@HeadCo unt", Data.SqlDbType. Int)
objCmd.Paramete rs("@HeadCount" ).Value = strHeadCount

objCmd.Paramete rs.Add("@STDHea dCount", Data.SqlDbType. Int)
objCmd.Paramete rs("@STDHeadCou nt").Value = strSTDHeadCount

objCmd.Paramete rs.Add("@Absent ", Data.SqlDbType. Int)
objCmd.Paramete rs("@Absent").V alue = strAbsent

objCmd.Paramete rs.Add("@rTO", Data.SqlDbType. Int)
objCmd.Paramete rs("@rTO").Valu e = strTO

objCmd.Paramete rs.Add("@Notes" , Data.SqlDbType. VarChar)
objCmd.Paramete rs("@Notes").Va lue = Notes2

objCmd.Paramete rs.Add("@RID", Data.SqlDbType. Int)
objCmd.Paramete rs("@RID").Valu e = strRID

I get System.FormatEx ception: Input string was not in a correct format.
error. Is this due to not having single qoutes around the varchar variables? I put in quoteReplace.st ring name and the app this it's an undeclared variable.
Oct 25 '07 #15
Plater
7,872 Recognized Expert Expert
I am guessing it has to do with the date parameter.
When you set the type to Date, the parameter expects you to add an object of type DateTime, not a string?
EDIT: actually the same holds true for all of them, the parameters of type Int, want you to add an object of type Int and not a string.
Oct 25 '07 #16
Plater
7,872 Recognized Expert Expert
What does this error mean?

BC31029: Method 'Protected Sub Page_Load(sende r As Object, e As System.EventArg s, rDate As Date, Shift As String, HeadCount As Integer, STDHeadCount As Integer, Absent As Short, rTO As Integer, Notes As String, RID As Integer)' cannot handle Event 'Public Event Load(sender As Object, e As System.EventArg s)' because they do not have the same signature.
it means you accidently deleted something and part of your page_load() function got overriden with the declaration of your other function.
Straighten out the functions and you should be fine.
Oct 25 '07 #17
BezerkRogue
68 New Member
it means you accidently deleted something and part of your page_load() function got overriden with the declaration of your other function.
Straighten out the functions and you should be fine.
Got them straightened out. I have remarked out all of the variables in the sp calls and executed it to see where I get a error. On the headcount variable I get a Object must implement IConvertible. error message. The first two pass fine.

Is this a bug or is there something that I didn't put in the code?
Oct 25 '07 #18
Plater
7,872 Recognized Expert Expert
strHeadCount is a string yes?
Convert it to an int with:
Int.Parse(strHe adCount)
Oct 25 '07 #19
BezerkRogue
68 New Member
strHeadCount is a string yes?
Convert it to an int with:
Int.Parse(strHe adCount)

It didn't like that line. Is there another way to cast a string to an int in VB.Net?
Oct 25 '07 #20

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

Similar topics

6
1613
by: Keiron Waites | last post by:
Please see the problem in action here: http://www.leadbullet.biz/contact.php If you mouse over the fields, you will see that text is shown on the right. The text makes the other fields move when it is shown - even though the width of the text is less than the width of the field. WHY? This is driving me nuts - please help! TIA,
12
1620
by: Marty | last post by:
It seems all of the sudden that user controls that contain images are referencing image sources relative to the document that I drop the control on. This obviously does not work beacuase the image source is relative to the user control, not necessarily the form. Can anyone tell me why this would be the case?
0
984
by: Simon Harris | last post by:
Ok, this really is driving me nuts!!! :( 'All' I am trying to do is get the value of a named element. My XML doc is: <?xml version="1.0" encoding="utf-16" standalone="yes" ?> - <Page> <Title>Test</Title> <MetaKeywords>Test</MetaKeywords>
2
1386
by: ipmccun | last post by:
Hello all: Perhaps someone can shed some light on this: I'm trying to create a situation, while debugging, where a long running request (sleeps for 15s) and a short running request execute concurrently. Right now, no matter what I do, it seems that they execute serially. I've verified (by watching netstat) that two simultaneous connections are being made to the server, so I'm sure this isnt the standard IE "only two connections to the...
4
1660
by: trond | last post by:
Hello all, Before I start I'd like to point out that I am a complete novice when it comes to asp.net - My background is in network and operating systems, and although I have been doing a bit of hobby programming in vb.net and web programming in asp/vbscript in the past, I am pretty much a beginner at asp.net. What I'm trying to do, is to take the "PersonalHomePage" starter kit that MS supplies with VS2005 and tweak it a bit, to make it...
2
1516
by: mitsura | last post by:
Hi, I need to read a simle XML file. For this I use the SAX parser. So far so good. The XML file consist out of number of "Service" object with each object a set of attributes. I read through the XML file and for each "<Service>" entry I create a new service object. When I am in the "<Service>" part of the XML file and I encounter
5
6865
by: jason.neo | last post by:
Hi all experts, I am going nuts with this Invalid postback or callback argument thingy with .Net 2.0 I am building a file attachment module which relays on a Datatable stored in session (yeah i know its unhealthy, but its the only "clean" approach which I can think of to avoid tranfering temp files onto the server) to maintain the list of attached files before the "commit" action is done to transfer all the files onto the server.
4
2475
by: mattlightbourn | last post by:
Hi all, I have a problem which has been driving me nuts. Crosstab queries! I have a database witch a few different tables to do with garment manufacturing. I have a table for a client account, garment type (Jacket, skirt, etc), client sizing spec and descriptives (measurement names i.e: Shoulder to cuff, inside leg, etc), available sizes (ie. 4,6,8,10,12,14,16,18,20,S,M,L,SM,ML,One) and pattern adjustments (if size 10 is the base, the...
3
2289
by: DuncanIdaho | last post by:
Hello experts IE 7.0.5730.11 Opera 9.27 Firefox 2.0.0.14 This problem only occurs in Opera and Firefox (amazing, IE does something right, or maybe not) Anyway, the problem is that when I put an image in a <divor a <td>
0
9710
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
9589
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,...
0
10593
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
10340
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
10329
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
9163
agi2029
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...
1
4304
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
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
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.