Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 11th, 2006, 01:35 PM
Authorized User
 
Join Date: Mar 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default Stored Procedures not working in Server Explorer

I have a stored procedure as follows:


(@PatientID as varchar, @dateIn as datetime)
AS
SELECT
    MriPatients.PatientID AS PatientID,
    MriPatients.Name AS Name,
    SchAppointments.Status AS Status,
    SchAppointments.AppointmentTypeID AS AppTypeID,
    SchAppointments.TypeDescription,
    SchAppointments.DateTime,
    SchAppointments.VisitID,
    SchEncounterForm.[Encounter Form],
    SchEncounterForm.Description
FROM
    MriPatients INNER
JOIN
    SchAppointments ON
        MriPatients.SourceID = SchAppointments.SourceID AND
        MriPatients.PatientID = SchAppointments.PatientID INNER JOIN
        SchEncounterForm ON SchAppointments.AppointmentTypeID = SchEncounterForm.[Appt Type]
WHERE
    (MriPatients.PatientID = @PatientID) AND
    (SchAppointments.Status = 'BOOKED') AND
    (CONVERT(char(10) , SchAppointments.DateTime , 101) = @dateIn)

This Procedure should return one row for a patient Appointment. In Query analyzer the query runs as expected and returns one row. In the VS IDE using Servr Explorer no rows are returned. Does anyone know why this wont work in Server Explorer. I suspect it is something simple like a dataType but I am only using two parameters.


 
Old October 12th, 2006, 10:22 AM
Authorized User
 
Join Date: Mar 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I ran a breakpoint in the SP and it is not the procedure that is failing.
 Here is the code that calls the SP:

Dim tmpCMD As New SqlCommand("PatientFormsByPatientID", DRSPLAT)
            Dim appDate As String = Convert.ToDateTime(EncounterForm.dateIN).ToString( "MM/dd/yyyy")
            Dim tmpDS As New DataSet
            With tmpCMD
                .CommandType = CommandType.StoredProcedure
                .Parameters.AddWithValue("@PatientID", PatientID)
                .Parameters.AddWithValue("@datein", appDate)
                .Parameters(0).Direction = ParameterDirection.Input
                .Parameters(1).Direction = ParameterDirection.Input
            End With
            Dim tmpDA As New SqlDataAdapter(tmpCMD)
            tmpDA.Fill(tmpDS) 'Aborts here

as you can see, the fill method of the Dataadapter is where the logic error is, and the adapter never fills, even though the SP returns 1 row.

 
Old October 13th, 2006, 09:52 AM
Authorized User
 
Join Date: Mar 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok I found the problem... if anyone cares

The parameter i was calling the SP with was not the same as in the SP .

this was the culprit line of code:
  .Parameters.AddWithValue("@datein", appDate)
 should have been "@dateIn"

always the little things...







Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows 2003 Server and Prepared Stored Procedures asawyer13 MySQL 0 June 30th, 2006 03:36 PM
No 'New Stored Procedure" in server explorer jkusmanto VS.NET 2002/2003 0 May 3rd, 2006 03:24 PM
Access, SQL Server - Stored Procedures / DTS tcarnahan Access 5 September 1st, 2004 05:17 AM
Professional Sql Server 7 Stored Procedures Darrell Clary All Other Wrox Books 0 October 8th, 2003 09:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.