S
Scott
Can someone please take a look at this code and tell me what I am
doing wrong. Basically, I am passing an ID value from the asp.net
page to a stored procedure for use in the WHERE clause of the SELECT
statement. I want the user to select the ID from a list and then
return all the details for editing the entry.
I've included the code and the stored procedure.
The error I am getting is:
System.Data.SqlClient.SqlException: Line 11: Incorrect syntax near
'45'.
Line 11 is: dtrPatient = cmd.ExecuteReader()
The '45' is the patientID being passed.
Code:
Dim PatientID As Integer
Dim cmd As SqlCommand
Dim dtrPatient As SqlDataReader
PatientID = Request.Params("PatientID")
cmd = dbConn.CreateCommand()
With cmd
.CommandText = "spPatientMaintain"
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@PatientID", SqlDbType.Int, 4)
.Parameters(0).Value = PatientID
End With
dtrPatient = cmd.ExecuteReader()
Stored Procedure (SqlServer):
CREATE PROCEDURE scott.spPatientMaintain (@PatientID as int)
AS
EXEC
('SELECT dbo.tblDoctor.DoctorName,
dbo.tblPatientAddress.PatientAddressTypeID,
dbo.tblPatientAddress.Address, dbo.tblPatientAddress.City,
dbo.tblPatientAddress.StateID,
dbo.tblPatientAddress.ZipCode,
dbo.tblPatientAddressType.AddressTypeDescription,
dbo.tblStateList.StateAbbreviation,
dbo.tblPatient.PatientID,
dbo.tblPatient.PatientNumber, dbo.tblPatient.LastName,
dbo.tblPatient.FirstName, dbo.tblPatient.HomePhoneNumber,
dbo.tblPatient.WorkPhoneNumber,
dbo.tblPatient.MobilePhoneNumber, dbo.tblPatient.Comments,
dbo.tblPatient.DoctorID,
dbo.tblPatient.EmailAddress
FROM dbo.tblPatientAddressType INNER JOIN
dbo.tblPatientAddress ON
dbo.tblPatientAddressType.PatientAddressTypeID =
dbo.tblPatientAddress.PatientAddressTypeID INNER JOIN
dbo.tblStateList ON
dbo.tblPatientAddress.StateID = dbo.tblStateList.StateID INNER JOIN
dbo.tblDoctor INNER JOIN
dbo.tblPatient ON dbo.tblDoctor.DoctorID =
dbo.tblPatient.DoctorID ON dbo.tblPatientAddress.PatientID =
dbo.tblPatient.PatientID
WHERE (dbo.tblPatientAddress.PatientAddressTypeID = 1) and
(dbo.tblPatient.PatientID=' + @PatientID)
GO
Any help is GREATLY appreciated.
doing wrong. Basically, I am passing an ID value from the asp.net
page to a stored procedure for use in the WHERE clause of the SELECT
statement. I want the user to select the ID from a list and then
return all the details for editing the entry.
I've included the code and the stored procedure.
The error I am getting is:
System.Data.SqlClient.SqlException: Line 11: Incorrect syntax near
'45'.
Line 11 is: dtrPatient = cmd.ExecuteReader()
The '45' is the patientID being passed.
Code:
Dim PatientID As Integer
Dim cmd As SqlCommand
Dim dtrPatient As SqlDataReader
PatientID = Request.Params("PatientID")
cmd = dbConn.CreateCommand()
With cmd
.CommandText = "spPatientMaintain"
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@PatientID", SqlDbType.Int, 4)
.Parameters(0).Value = PatientID
End With
dtrPatient = cmd.ExecuteReader()
Stored Procedure (SqlServer):
CREATE PROCEDURE scott.spPatientMaintain (@PatientID as int)
AS
EXEC
('SELECT dbo.tblDoctor.DoctorName,
dbo.tblPatientAddress.PatientAddressTypeID,
dbo.tblPatientAddress.Address, dbo.tblPatientAddress.City,
dbo.tblPatientAddress.StateID,
dbo.tblPatientAddress.ZipCode,
dbo.tblPatientAddressType.AddressTypeDescription,
dbo.tblStateList.StateAbbreviation,
dbo.tblPatient.PatientID,
dbo.tblPatient.PatientNumber, dbo.tblPatient.LastName,
dbo.tblPatient.FirstName, dbo.tblPatient.HomePhoneNumber,
dbo.tblPatient.WorkPhoneNumber,
dbo.tblPatient.MobilePhoneNumber, dbo.tblPatient.Comments,
dbo.tblPatient.DoctorID,
dbo.tblPatient.EmailAddress
FROM dbo.tblPatientAddressType INNER JOIN
dbo.tblPatientAddress ON
dbo.tblPatientAddressType.PatientAddressTypeID =
dbo.tblPatientAddress.PatientAddressTypeID INNER JOIN
dbo.tblStateList ON
dbo.tblPatientAddress.StateID = dbo.tblStateList.StateID INNER JOIN
dbo.tblDoctor INNER JOIN
dbo.tblPatient ON dbo.tblDoctor.DoctorID =
dbo.tblPatient.DoctorID ON dbo.tblPatientAddress.PatientID =
dbo.tblPatient.PatientID
WHERE (dbo.tblPatientAddress.PatientAddressTypeID = 1) and
(dbo.tblPatient.PatientID=' + @PatientID)
GO
Any help is GREATLY appreciated.