Chris Jones
asked on
straneg MSSQL erorr using VB
Hello
i have this code that worked 2 days ago but now its not working and nothing has been chaged dealing with the code as well as the data.
here is the eror i get
UserID
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeExce ption: UserID
Source Error:
Line 33: dr = sql.ExecuteReader()
Line 34: If dr.Read() Then
Line 35: TempuserID = dr("UserID")
Line 36: conn = D.NewSQLConnectionWebApp()
Line 37: sqlUpdate.Connection = conn
HERE IS THE CODE
i have this code that worked 2 days ago but now its not working and nothing has been chaged dealing with the code as well as the data.
here is the eror i get
UserID
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeExce
Source Error:
Line 33: dr = sql.ExecuteReader()
Line 34: If dr.Read() Then
Line 35: TempuserID = dr("UserID")
Line 36: conn = D.NewSQLConnectionWebApp()
Line 37: sqlUpdate.Connection = conn
HERE IS THE CODE
Private Sub verifyuser(ByVal MID As String)
Dim sql As New SqlCommand
Dim sqlUpdate As New SqlCommand
Dim dr As SqlDataReader
Dim conn As SqlConnection
Dim TempuserID As String
conn = D.NewSQLConnectionWebApp()
sql.Connection = conn
sql.Parameters.AddWithValue("@ID", MID)
sql.CommandText = "SELECT * FROM Buddy_User WHERE Code = @ID"
dr = sql.ExecuteReader()
If dr.Read() Then
TempuserID = dr("UserID")
conn = D.NewSQLConnectionWebApp()
sqlUpdate.Connection = conn
sqlUpdate.Parameters.AddWithValue("@ID", MID)
sqlUpdate.CommandText = "UPDATE Buddy_User SET Active ='Y' WHERE Code = @ID"
sqlUpdate.ExecuteNonQuery()
Response.Redirect("Home.aspx")
End If
dr.Close()
sql.Dispose()
sqlUpdate.Dispose()
conn.Close()
' A.SaveImage("./UserData/placeholder.jpg", TempuserID)
end sub
Can you send the output from
EXECUTE sp_help Buddy_User
EXECUTE sp_help Buddy_User
ASKER
@ c1nmo: what were you needing there is a lot of values that are returned.
ASKER
@yv989c: here is my table structure
USE [cjones12_Wedding]
GO
/****** Object: Table [defjam903].[Buddy_User] Script Date: 09/03/2011 10:50:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [defjam903].[Buddy_User](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Username] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Password] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Email] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[School] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Code] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Active] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_Buddy_User_Active] DEFAULT ('N'),
[MemberSince] [datetime] NULL CONSTRAINT [DF_Buddy_User_MemberSince] DEFAULT (getdate())
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
ASKER
oh no wait a moment there is no column name UserID WOW!!
Hello, that is the problem, the [Buddy_User] table don't has a column named UserID, I think that correct column name is ID, but I can't be sure, so try change this line (#14 of your example):
I hope this help.
TempuserID = dr("UserID")
to:TempuserID = dr("ID")
I hope this help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Open in new window
Is returning a column named UserID ? be sure of that.