Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 22nd, 2003, 03:52 AM
Jalil Jalil is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Bangladesh
Posts: 1 Jalil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Stored Procedure

Hye
Please read the following and reply me with solution

suppose there is a database in sql server named test, a table named tbltest and a stored procedure named sptest within this database.

tbltest hase two fields say a(int), b(varchar(10))

stored procedure sptest is given below:

/*start of stored procedure*/
create procedure sptest as
declare @n int
if (select count(a) from tbltest)=0
select @n=0
else
select @n=max(a) from tbltest

insert tbltest values(@n+1, 'zzzzzz')

select * from tbltest
/*end of stored procedure*/

vb-ide details
reference used: Microsoft ActiveX Data Object 2.5 Library
project type: standard.exe
form: a single form within this project

vb code is given below:

/* general section start*/
Dim cmm As ADODB.Command
Dim rs As ADODB.Recordset
/* general section end*/

Private Sub Form_Load()
Set cmm = New ADODB.Command
Set rs = New ADODB.Recordset

With cmm
.ActiveConnection = "Provider=SQLOLEDB.1;User ID=sa;Initial Catalog=test;Data Source="Please use your database server name here""
.CommandType = adCmdStoredProc
.CommandText = "sptest"
End With

rs.Open cmm, , adOpenKeyset, adLockOptimistic
MsgBox rs.Fields(0)
End Sub


operating system used: Windows XP professional
database used: SQL Server 7.0
vb-ide: Visual Basic 6.0

my comments:
when stored procedure sptest execute (i.e. i run the vb project) it can insert values to table tbltest but the select statement following insert statement does not execute (i may be wrong).

please give me the solution. but change in stored procedure is not allowed; also VB data access reference

Reply With Quote
  #2  
Old August 1st, 2003, 11:30 AM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
your messagebox will always show the same value, since you select the first row, first column in the recordset.

I you would like to see the inserted number you have to scroll in the recordset to the last record and display that.

If you, in your stored procedure do a select * from tbltest where a = @n, you will receive a one row recordset and the rs.Fields(0) will return the a column value of the newly inserted row.

You could accomplish the same thing if you just make the last statement in your stored procedure as select @n.

Thanks,
__________________
- Rogier Doekes

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > Stored Procedure


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT