aina — 2010-08-30T13:39:33-04:00 — #1
I am not sure where my app is failing but most probably this is where it is failing.. I think lblExpID.Text is the culprit. Here's the relvant part of my code:
Dim lblExpID As Label
For Each item In LSGrid.Rows
lblExpID = item.FindControl("lblID")
If txtExpGenFund.Text <> "" Then
sqlArray(i) = ExpDetailsID & "," & (lblExpID.Text) & "," & MunID & "," & _
Val(txtExpGenFund.Text) & "," & Val(txtExpDetSpecialRevenue.Text) & "," & _
Val(txtExpDetCapitalProjects.Text) & "," & expTotal & "," & reportingYear & "," & "Test Comments" & "," & UserID
Can u help me identify why i am getting this error looking at the sp below:
@ExpDetailsID int=0 output,
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
delete from [dbo].[TBL_EXPENDITURE_DETAILS] where ExpDet_ExpID=@ExpDet_ExpID and ExpDet_Municipality_ID=@ExpDet_Municipality_ID and Exp_Reporting_Year=@Exp_Reporting_Year
If @ExpDetailsID >= 0
INSERT INTO [dbo].[TBL_EXPENDITURE_DETAILS]
SET @ExpDetailsID = SCOPE_IDENTITY()
serenarules — 2010-09-01T12:59:14-04:00 — #2
As far as I recall, with VB you can concat string and ints into a single string without converting. I could be wrong though so don't take it for granted. Anyway, the result of &ing things together like that will be a string.
Part of the problem in us helping is that we aren't seeing all the code or how it's being used in conjunction with the stored proc. I am assuming this bit is in a loop to incremement the index "i"? Anyway, since you're assigning a long concatenated string to that array index, try setting it to a value first, and either put a watch, or beakpoint on it to see if that's where the error actually is.
Dim testVal as String
testVal = ExpDetailsID & "," & (lblExpID.Text) & "," & MunID & "," & _ ' plus the rest
sqlArray(i) = testVal ' set break here and inspect testVal
If it makes it there without causing an exception, and testVal has the right value, then the error is somewhere else.
I fyour intent is to collect params for the stored proc, then you probably need to use a multidimensional array and set each element to a specific value. It looks like you're hoping the commas you're including will be enough to delimit params.
for r = 0 to rowCount step 1
sqlArray(r, ID1_INDEX) = id1
sqlArray(r, ID2_INDEX) = TextBox1.Text
' and so one, loop through the rows, and use consts to define your param indexes.
My VB syntax might be a bit off, it's been about 5 years since I've touched it. And if my hunches here are wrong also, just disregard the post.
jamietownsend — 2010-09-01T11:12:32-04:00 — #3
Glad it worked
jason__c — 2010-08-30T20:04:56-04:00 — #4
Is this VB Script (ASP)? Might want to move it to the classic ASP Forum. Then again, I don't use VB.NET, just looks different.
matt_daly — 2010-08-31T22:18:02-04:00 — #5
ExpDet_ExpID is an integer in your stored procedure, you need to parse lblExpID.Text before you pass it into the query.
chroniclemaster1 — 2010-08-31T21:19:54-04:00 — #6
Does it give you a line number? In my experience a stored procedure error is typically not that specific; I usually get "Something went screwy" and you dig a little deeper and find that it probably is a problem down in the stored proc. So by the error message you're getting, I would actually suspect that the problem is in a line of the program code. Possibly sneaky one where you've implicitly passed a string that looks like an int to another variable.
serenarules — 2010-09-01T20:36:40-04:00 — #7
Odd, the two posts above mine weren't showing when I posted. Glad you got it worked out.
aina — 2010-09-01T10:58:06-04:00 — #8
YOU R THE BEST Jamie. Ya it worked. Three cheers to you...:-)
jamietownsend — 2010-09-01T10:38:55-04:00 — #9
Ok, for starters, if lblExpID.Text fails in it's conversion to Int what do you want to happen ?
My reply still stands for converting to Int, VB would be something like:
Dim iExpId As Integer
If (Int32.TryParse(lblExpID.Text, iExpId)) Then
// valid int
// invalid int
aina — 2010-09-01T10:35:10-04:00 — #10
This is VB.NET. I am using VS framework 3.5
aina — 2010-09-01T10:33:29-04:00 — #11
Nothing is working so far..i have tried everything..please help.. I need to submit this day after tomorrow:-(
aina — 2010-09-01T13:26:43-04:00 — #12
GOT MY REPLY.. please follow JamieTownsend answers if you have similar issue
jamietownsend — 2010-09-01T09:45:18-04:00 — #13
do not use parse as it will return an exception if fails.
use something like this:
if (Int32.TryParse(lblExpID.Text, out iExpId))
// valid int
// fail or do something else