473,499 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to call stored procedure in vb.net

1 New Member
I have stored procedure in sql server as follows

Expand|Select|Wrap|Line Numbers
  1. USE [KHHAPS1]
  2. GO
  3. /****** Object:  StoredProcedure [dbo].[sp_transcrt]    Script Date: 09/30/2014 16:22:48 ******/
  4. SET ANSI_NULLS OFF
  5. GO
  6. SET QUOTED_IDENTIFIER OFF
  7. GO
  8. -- Used to Create the HAPSTran Table By copying All Required fields from HAPSMast Table
  9. -- @YrMn  contains the present YearMonth value
  10. create PROCEDURE [dbo].[sp_transcrt]
  11. @YrMn as char(6),
  12. @TypeInst as varchar(6),
  13. @User as varchar(3),
  14. @Cnt as int OUTPUT as
  15. declare @TTableName as Char(11)
  16. select @TTableName='TT' +  @TypeInst+@User
  17. declare @m1 as int
  18. declare @YrMn2 as char(6)
  19. select @m1=convert(int,right(@YrMn,2))
  20. if @m1=1 
  21. begin
  22. declare @y1 as int
  23. select @y1=convert(int,left(@YrMn,4))
  24. select @y1=@y1-1
  25. select @YrMn2=CONVERT(CHAR(4),@y1)+'12'
  26. end
  27. else
  28. begin
  29. select @m1=@m1-1
  30. declare @mm as char(2)
  31. if @m1<10 
  32. select @mm='0' + convert(char(1),@m1)
  33. else
  34. select @mm= convert(char(2),@m1)
  35. select @YrMn2= left(@YrMn,4)+@mm
  36. end
  37. insert  HAPSTran(InstId,EmpCode,Yrmn,DeptCode,UnitCode,HapsCat,Basic,Basic35,SpfAmt,Mhap,Haps3,Short,Incentive,Eligible,EveAct,EveElg,Arrears,Gross,Tds,Deduction,Net,HAPS,Variable,AGP,hapsperc,userid,Datem,timem,Moddate,Moduser) select @TypeInst,EmpCode,@YrMn,DeptCode,UnitCode,HapsCat,Basic,0,PLI,0,0,0,0,0,0,0,0,0,0,0,0,'Y',Variable,AGP,HapsPerc,@User,getdate(),null,null,null
  38. from HAPSMast where active <> 'N' AND HAPSMast.InstId = @TypeInst
  39. UPDATE HAPSTran 
  40. SET basic35 =  ROUND((b.basic+a.AGP) * (cast(a.NPAPerc as float) / CAST(100 AS FLOAT)),0) from HAPSMAST a INNER JOIN HAPSTran b ON A.Empcode = B.Empcode AND A.InstId = B.InstId where b.yrmn = @Yrmn AND A.InstId = @TypeInst AND b.InstId = @TypeInst
  41. UPDATE HAPSTran 
  42. SET WDays =  (select nodays from hapscutoff ) where unitCode='ANS001' and  yrmn = @Yrmn 
  43.  
  44. UPDATE HAPSTran 
  45. SET WDays =  0 where unitCode <> 'ANS001' and  yrmn = @Yrmn 
and I want to call this in vb.net. please send the source code
Sep 30 '14 #1
1 1470
Frinavale
9,735 Recognized Expert Moderator Expert
Use the SqlConnection class to open a connection to your database and use the SqlCommand Class to execute a command that calls your stored procedure.

For example:
Expand|Select|Wrap|Line Numbers
  1.   Dim connectionString As String = "Server=ipOfSQLServerHost;Database=DatabaseName;User ID=userID; Password=theDatabasePassword;" 'your specific connection string needs to go here
  2.   Dim queryString As String= "sp_transcrt"
  3.   Dim output As String
  4.  
  5.   Using connection As New SqlConnection(connectionString)
  6.  
  7.       Dim command As New SqlCommand(queryString, connection)
  8.       command.CommandType = CommandType.StoredProcedure
  9.  
  10.       command.Parameters.Add("@YrMn", SqlDbType.VarChar, 6)
  11.       command.Parameters.Add("@TypeInst", SqlDbType.VarChar, 6)
  12.       command.Parameters.Add("@User", SqlDbType.VarChar, 6)
  13.       command.Parameters.Add("@Cnt", SqlDbType.VarChar)
  14.       command.Parameters("@Cnt").Direction = ParameterDirection.Output
  15.  
  16.       command.Connection.Open()
  17.  
  18.       Dim numRows As Integer = command.ExecuteNonQuery()
  19.       If IsDBNull(command.Parameters("@Cnt").Value) = False Then
  20.             output = command.Parameters("@Cnt").Value
  21.       End If
  22.  
  23.   End Using 
Oct 2 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2259
by: Luis | last post by:
I'm using code similar to the following in an asp page to call a stored procedure that does a select on a SQLServer 2000 table: dim rs, SelectSql SelectSql = "EXEC spSelectStuff @param = '" &...
2
9712
by: syoung | last post by:
I would like to know if anyone knows how to execute a stored procedure from ASP.NET 2.0. I'm using the NorthWind database and I'm trying to execute the "CustOrderHist" stored procedure. The...
1
1813
by: Jenny C. | last post by:
Hi I am fairly new to .NET, and I am having a hard time to call a stored procedure from C# code in a windows application I have tested my connection (and login) several time and it is OK. If I...
6
2303
by: Sam | last post by:
I had created stored procedure at SQL Server 2000 and how do I call it via ASP.Net using VB Language? CREATE PROCEDURE STK As if exists (select * from dbo.sysobjects where id =...
3
7205
by: sarma | last post by:
Hi friends, I created a stored procedure in MySQL like create procedure p() select NOW(); I write a C program, from which i wish to call this stored procedure, i used both...
3
3288
by: JM | last post by:
Hi, I am using SQL Server 2000 and ASP.NET 2.0 and want to call a stored procedure using Latest Enterprise Library 2.0. My stored procedure has 3 input parameters: CustId (int), RefId(int) and...
1
3798
by: eholz1 | last post by:
Hello PHP Group, Is there any advantages (or disadvantages) in using mysqli instead of mysql (querys, connections to database, etc). I am currently using mysql_connect, and things like this:...
0
3787
by: pbaillard | last post by:
Here a sample to call a stored procedure with an Oracle Database. odc.Connection = m_cDb ' use an open connection to your database odc.CommandType = CommandType.StoredProcedure odc.CommandText =...
2
2978
by: E11esar | last post by:
Hello there. I am going in bit of a circle with this matter; First some background: I am trying to upload the details of a CSV file into an Oracle table. I am using a StreamReader to copy a line...
3
7651
akashazad
by: akashazad | last post by:
Hi Friends My question is "can we call Stored Procedure from a User Defined Function in SQL" If yes then pl tell me how? If No then pl tell me why not ? While I was trying finding...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.