|
-
Nov 19th, 2002, 05:22 AM
#1
Thread Starter
Lively Member
stored procedure (parameter)
hi
is there a way for giving parameters to a stored procedure without using command.parameters.add method?. In vb6, we could've given parameters directly with connection.execute.
please help
when in doubt, win the trick
-
Nov 19th, 2002, 10:37 AM
#2
Hyperactive Member
VB Code:
Dim cmd As SqlCommand = New SqlCommand("Exec usp_Authors_f @au_id='123-56-1234'")
-
Nov 20th, 2002, 04:20 AM
#3
Thread Starter
Lively Member
hi
thanks. but it gave an sqlexception error.
any suggetions?
thanks
when in doubt, win the trick
-
Nov 20th, 2002, 04:28 AM
#4
Addicted Member
hi,
it should be:
VB Code:
Dim cmd As SqlCommand = New SqlCommand("Exec usp_Authors_f @au_id='123-56-1234'", MyConnection)
-
Nov 20th, 2002, 04:55 AM
#5
Thread Starter
Lively Member
hi
ofcourse I tried that. Then I got that error.
any idea?
when in doubt, win the trick
-
Nov 20th, 2002, 10:57 AM
#6
Hyperactive Member
um, i only posted the part you needed, hence, no connection information, you don't have to put the connection reference in the initializer(you can do that later).
VB Code:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Public Module TestCommand
Public Sub Main()
Dim connString As String = "user id=sa;password=sa;database=pubs;server=Manson;"
Dim cn As SqlConnection = New SqlConnection(connString)
Dim cmdText As String = "Exec usp_Author_f '274-80-9391'"
Dim cmd As SqlCommand = New SqlCommand(cmdText, cn)
Dim dr As SqlDataReader
Try
cmd.Connection.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.Read() Then
Console.WriteLine("Author's last name is {0}", dr("au_lname"))
End If
Catch sqlEx As SqlException
Console.WriteLine("Sql Exception: " & sqlEx.Message)
Catch ex As Exception
Console.WriteLine("Exception: " & ex.Message)
Finally
If Not dr Is Nothing Then
dr.Close()
End If
cmd.Dispose()
cn.Dispose()
End Try
Console.WriteLine("Press <Enter> to exit...")
Console.ReadLine()
End Sub
End Module
Here's the stored proc i'm calling:
Code:
Create Procedure usp_Author_f
@au_id id
As
Set Nocount On
Select
*
From
Authors
Where
au_id=@au_id
Set Nocount Off
go
-
Nov 21st, 2002, 01:02 AM
#7
Thread Starter
Lively Member
Thank you very much Mr.PVB
the problem was I gave command.commandType as commandType.StoredProcedure. it's only text. right?
Thanks again
when in doubt, win the trick
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|