|
-
Mar 3rd, 2005, 12:42 PM
#1
Thread Starter
Hyperactive Member
[Resolved]Is VB.NET or C# able to use Store Procedure?
Hi all,
I want to build one website that using VB.NET or C#
but I'm really dont want to use dynamic sql.
I would to use stored procedure.
If it possible, can some one give me a simple of code
that shows how to use stored procedure, how to send a parameter?
Thanks for all
Last edited by naruponk; Mar 6th, 2005 at 12:50 AM.
-
Mar 3rd, 2005, 01:05 PM
#2
Lively Member
Re: Is VB.NET or C# able to use Store Procedure?
Try this:
VB Code:
Dim Conn As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=databasename")
Dim slsCMD As OleDbCommand = New OleDbCommand("SalesByCategory", Conn)
slsCMD.CommandType = CommandType.StoredProcedure
Dim myParm As OleDbParameter = slsCMD.Parameters.Add("@CategoryName", OleDbType.VarChar, 15)
myParm.Value = "yourParameterValue"
Conn.Open()
//DO STUFF
Conn.Close()
-
Mar 4th, 2005, 09:04 PM
#3
Thread Starter
Hyperactive Member
Re: Is VB.NET or C# able to use Store Procedure?
I got an error this line
Value of type 'String' cannot be converted to 'System.Data.OleDb.OleDbParameter'.
VB Code:
Dim myParm As OleDbParameter = "slsCMD.Parameters.Add(@MemberName,OleDbType.Bigint, ,1)
VB Code:
Dim slsCMD As OleDbCommand = New OleDbCommand("SalesByCategory", Conn)
Is "SalesByCategory" to define a Stored Procedure name?
Last edited by naruponk; Mar 4th, 2005 at 09:24 PM.
-
Mar 5th, 2005, 01:18 AM
#4
Re: Is VB.NET or C# able to use Store Procedure?
VB Code:
Dim myParm As OleDbParameter = [b]"[/b]slsCMD.Parameters.Add(@MemberName,OleDbType.Bigint, ,1)
you get that error because you have " around the slscmd.Parameters.add....
VB Code:
Dim Conn As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI;" & _
"Initial Catalog=databasename")
Dim slsCMD As OleDbCommand = New OleDbCommand("[Insert Stored proc name Here!]", Conn)
slsCMD.CommandType = CommandType.StoredProcedure
Dim myParm As OleDbParameter = slsCMD.Parameters.Add("@[Parameter Name Here]", OleDbType.VarChar, 15) ' Change OleDbType.VarChar to the proper type for the param
myParm.Value = "yourParameterValue" ' set the value here
Conn.Open()
'Now do a
slsCMD.ExecuteScalar ' if one value is returned
'or
slsCMD.ExecuteNonQuery ' if no values are returned
'ect...
Conn.Close
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Mar 5th, 2005, 03:56 AM
#5
Thread Starter
Hyperactive Member
Re: Is VB.NET or C# able to use Store Procedure?
Ok, below are my code for this thread.
What's wrong of this code?
<%@ Import NameSpace="System.Data.OLEDB" %>
<% Dim Conn As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=ServerName;Integrated Security=SSPI;Initial Catalog=DatabaseName")
Dim slsCMD As OleDbCommand = New OleDbCommand("StoredProcName", Conn)
slsCMD.CommandType = "CommandType.StoredProcedure"
Dim myParm As OleDbParameter = slsCMD.Parameters.Add("@MemberName",OleDbType.Bigint, ,1)
myParm.Value = 1
Conn.Open()
Conn.Close()
%>
Thanks
-
Mar 5th, 2005, 04:14 AM
#6
Re: Is VB.NET or C# able to use Store Procedure?
 Originally Posted by naruponk
Ok, below are my code for this thread.
What's wrong of this code?
<%@ Import NameSpace="System.Data.OLEDB" %>
<% Dim Conn As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=ServerName;Integrated Security=SSPI;Initial Catalog=DatabaseName")
Dim slsCMD As OleDbCommand = New OleDbCommand("StoredProcName", Conn)
slsCMD.CommandType = "CommandType.StoredProcedure"
Dim myParm As OleDbParameter = slsCMD.Parameters.Add("@MemberName",OleDbType.Bigint, ,1)
myParm.Value = 1
Conn.Open()
Conn.Close()
%>
Thanks 
ok make your code like this one.
VB Code:
Dim Conn As New OleDbConnection("Provider=SQLOLEDB;Data Source=ServerName;Integrated Security=SSPI;Initial Catalog=DatabaseName")
Dim slsCMD As New OleDbCommand()
slsCMD.CommandText = "StoredProcName"
slsCMD.CommandType = CommandType.StoredProcedure
slsCMD.Connection = Conn
slsCMD.Parameters.Add("@MemberName", textbox1.text)
Conn.Open()
slsCMD.executenonquery
Conn.Close()
-
Mar 6th, 2005, 12:50 AM
#7
Thread Starter
Hyperactive Member
Re: Is VB.NET or C# able to use Store Procedure?
OK, Resolved!
Thanks for all help
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
|