Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6
This is the forum to discuss the Wrox book ASP.NET 2.0 Instant Results by Imar Spaanjaars, Paul Wilton, Shawn Livermore; ISBN: 9780471749516
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 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 31st, 2006, 05:33 PM
Authorized User
 
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert Procedure

Hello,

I love the book.
I am using the examples in the book to build applications.
One wall Ive run into though....
I am entering users based on last name, first name into a SQL database. Im using a stored procedure to do this and in the sp i check if the last name, first name exist already somewhere in the db.
If so I want to be able to pass back an output parameter and also a resultset of the lastname, firstname row that exist and their id(autoidentity). I have succeded in doing this. I then want to inform the user that this name already exists in the database...but i want to take it a bit further and display the row with that firstname, last name combination and give the user the option to edit that existing row. How can I go about retrieving the output parameter AND the resultset in a vb.net function?? This is what puzzles me. Im hoping if the insert is unsuccessful (meaning the name alrady exists) that i can return a value (-1) and a select query of the existing name. How can I handle this with a vb.net function in a DAL?
The reason for this is I want to keep track of students and what bus they are riding to/from school. One student can only exist on one bus. So if the secretary is entering a student i want them to be informed if a student already exists on another bus, and i want to retrieve that record and give the secretary the option to edit that row....any suggestions?
let me know if i need to do more explaining

 
Old October 31st, 2006, 06:02 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi cf2006,

Glad you like the book.

Quick question before I give you a longer answer (which may take some time, kinda busy at the moment). Are you using a specific application from the book for your own project? Are you basing this on the Appointment Booking app?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old October 31st, 2006, 06:15 PM
Authorized User
 
Join Date: Jul 2006
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

Thanks for the quick reply. No, im not basing it off of that...should I be looking at that one? Im just kind of using bits and pieces of ch 12 and 5....I noticed in Ch5 that you inform the user when they enter a category that already exists. i just want to go a little further than that. Im stumped though... :(
My eyes hurt and all the words are beginning to run together
thanks
justin

 
Old October 31st, 2006, 06:28 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi justin,

No, you don't necessarily have to look at the Appointment booking app. However, if you were basing this on an existing app, it would be easier for me to show you code that plugs right into your application.

Basically what you need to do is this:

1. Create a stored procedure with an OUTPUT param. This sproc should select the result set AND fill in the OUTPUT param. You can use IF EXISTS in the query to see if the record already exists.

2. Next, you need to set up this param in the DAL and pass it into the Command object.

3. When the query is executed, get the resultset (a DataSet or a SqlDataReader) and get the value from the output param.

4. Give the method that calls this code a return type of the initial data (e.g. a User object, or a DataSet, or a List (Of Users), whatever is appropriate.) Also, if necessary, give it a ByRef param to indicate if the record already exists.

Now, this is the hard way to do things. You want to return an OUTPUT param AND a resultset at the same time. But maybe you can do this much simpler? What about this (pseudo code):

Public Function CheckUser(ByVal userId As Integer)
  ' Go into database
  If the user exists in the database
    Return New User(FirstName from database, LastName from database)
  Else
    Return Nothing
  End If
End Function

Then in your calling code you can do this:

If CheckUser(someId) Is Nothing Then
  ' User is not on the bus
Else
  Sorry, this user is already on the bus. Would you like to edit it?
End If

If you need help with the first scenario (or with the second), let me know. A verbose answer may take until the weekend as I don't much time earlier.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
 
Old November 6th, 2006, 01:58 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi justin,

Are you making any progress with this? Did my general outline help you to get started?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesn't this Insert Procedure work. beerOne ASP.NET 3.5 Basics 2 June 19th, 2008 09:59 AM
Stored Procedure Insert Null Value harpua SQL Server ASP 2 March 5th, 2005 10:19 AM
stored procedure dynamic insert harpua Classic ASP Databases 3 January 21st, 2005 12:50 AM
How do I insert stored procedure through C# nishim.attreja VB How-To 1 September 18th, 2004 01:24 AM
Using an insert stored procedure morpheus VB How-To 3 August 7th, 2003 08:42 AM





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