February 20, 2009 at 2:46 am
Hi friends ..
Can you tel me how to call stored procedures through vb.net coding..
Thanks and Regards
Shobana
February 20, 2009 at 7:47 am
You would do something like this:
Imports System.Data.SQLClient
Dim cnSQL as SQLConnection = New SQLConnection(ConnectionString)
Dim cmdSQL as new SQLCommand
' if you want to return results using a datareader then you need a SQLDataReader
Dim dr as SQLDataReader
' if you want to return results using a dataset/datatable then you need a SQLDataAdapter
' and a dataset or datatable
Dim da as SQLDataAdapter = New SQLDataAdapter(cmdSQL)
Dim ds as DataSet
' if you are not returning data then you do not need anything else
With cmdSQL
.Connection = cnSQL
.CommandType = storedprocedure
.CommandText = "stored procedure name"
' now add parameters
.Parameters.AddWithValue("parameter name", value)
' open the connection
cnSQL.Open()
' for a procedure that returns no resultset
.ExecuteNonQuery()
' for a procedure to return a datareader (you need to create the
drSQL = .ExecuteDataReader()
' to return a dataset
da.Fill(ds)
End With
Edited to remove the horizontal scroll (at least on my screen):w00t:
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply