473,788 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stored Procedures

Hey there,

I think this is not actually VB, but the language im using is VB. Ive
been doing all my code,, NOT using Stored procedures.. so my functions
are like.(in 2003)

visual basic
code:--------------------------------------------------------------------------------
Public Function vLookup(ByVal table As String, ByVal returnColumn As
String, ByVal checkColumn As String, ByVal checkValue As String) As
String
Dim StringToReturn As String

StringToReturn = ""
Dim SQL As String
SQL = "SELECT " + returnColumn + " from " + table + " where " +
checkColumn + " = " + checkValue + ""

Dim dataAdapter As System.Data.Ole Db.OleDbDataAda pter
dataAdapter = New System.Data.Ole Db.OleDbDataAda pter(SQL,
Me.OleDbConnect ion1)
Try
Dim dt As System.Data.Dat aTable
dt = New System.Data.Dat aTable
dataAdapter.Fil l(dt)
If dt.Rows.Count 0 Then
If dt.Rows(0).Item Array.Length 0 Then
StringToReturn = CStr(dt.Rows(0) .Item(0))
End If
End If
Catch
StringToReturn = "-1"
End Try

Return StringToReturn
End Function

--------------------------------------------------------------------------------
MY question is how do I change this to function to us a stored
procedure that does the same thing. Stored procedures are in SQL server
2000? Now using .net 2005

lets call the stored proecedure stoCustomer

thanx in advance

Sep 12 '06 #1
6 3428
Looking at your SQL statement, a "normal" stored procedure won't be
able to replace it. You'll have to use a stored procedure that uses
dynamic SQL. You may want to search the comp.databases. ms-sqlserver
newsgroup on what this means and how to write one. Also check out
http://support.sas.com/ctx/samples/index.jsp?sid=817 it's a great
article on using both ADO and ADO.NET to call stored procs with VB.NET
and C#. If you need further help please post again and I'll try to walk
you through whatever you need.

Thanks,

Seth Rowe
Bonzol wrote:
Hey there,

I think this is not actually VB, but the language im using is VB. Ive
been doing all my code,, NOT using Stored procedures.. so my functions
are like.(in 2003)

visual basic
code:--------------------------------------------------------------------------------
Public Function vLookup(ByVal table As String, ByVal returnColumn As
String, ByVal checkColumn As String, ByVal checkValue As String) As
String
Dim StringToReturn As String

StringToReturn = ""
Dim SQL As String
SQL = "SELECT " + returnColumn + " from " + table + " where " +
checkColumn + " = " + checkValue + ""

Dim dataAdapter As System.Data.Ole Db.OleDbDataAda pter
dataAdapter = New System.Data.Ole Db.OleDbDataAda pter(SQL,
Me.OleDbConnect ion1)
Try
Dim dt As System.Data.Dat aTable
dt = New System.Data.Dat aTable
dataAdapter.Fil l(dt)
If dt.Rows.Count 0 Then
If dt.Rows(0).Item Array.Length 0 Then
StringToReturn = CStr(dt.Rows(0) .Item(0))
End If
End If
Catch
StringToReturn = "-1"
End Try

Return StringToReturn
End Function

--------------------------------------------------------------------------------
MY question is how do I change this to function to us a stored
procedure that does the same thing. Stored procedures are in SQL server
2000? Now using .net 2005

lets call the stored proecedure stoCustomer

thanx in advance
Sep 12 '06 #2
Thanx for your reply

Yeah I think I need some help. I had a look, but im only a beginner.

My connection string is

Me.OleDbConnect ion1 = New System.Data.Ole Db.OleDbConnect ion
Me.OleDbConnect ion1.Connection String = "Integrated
Security=SSPI;P acket Size=4096;Data Source=""PIGMAN IA"";Tag with " & _
"column collation when possible=False; Initial
Catalog=Northwi nd;Use Procedure fo" & _
"r Prepare=1;Auto Translate=True; Persist Security
Info=False;Prov ider=""SQLOLEDB .1" & _
""";Worksta tion ID=ASPNET;Use Encryption for Data=False"

that works.

Just showing me how to use that to call a storedprocedure to fill a
datatable(also an example with storeprocedure imputs would be nice),
would be really nice. then I can learn from that example. I found it
hard to find any examples that showed me exactly this.

Thanx in advance

Sep 12 '06 #3
Try this for the data adapter code. -- Not tested

(I would add the below imports statement)
Imports System.Data.Ole Db

' Instantiate the DataAdapter and supply it the target
' stored procedure name and your connection variable
Dim DataAdapter as New OleDbDataAdapte r("stoCustomer" ,
OleDbConnection 1)
' Add the new parameter's name, type, and size
DataAdapter.Sel ectCommand.Para meters.Add("@Cu stName",
OleDbType.VarCh ar, 50)
' Assign the new parameter a value
DataAdapter.Sel ectCommand.Para meters("@CustNa me").Value = "Maria
Anders"

You should be ok to fill your datatable from there. If not please post
back.

Thanks,

Seth Rowe

Bonzol wrote:
Thanx for your reply

Yeah I think I need some help. I had a look, but im only a beginner.

My connection string is

Me.OleDbConnect ion1 = New System.Data.Ole Db.OleDbConnect ion
Me.OleDbConnect ion1.Connection String = "Integrated
Security=SSPI;P acket Size=4096;Data Source=""PIGMAN IA"";Tag with " & _
"column collation when possible=False; Initial
Catalog=Northwi nd;Use Procedure fo" & _
"r Prepare=1;Auto Translate=True; Persist Security
Info=False;Prov ider=""SQLOLEDB .1" & _
""";Worksta tion ID=ASPNET;Use Encryption for Data=False"

that works.

Just showing me how to use that to call a storedprocedure to fill a
datatable(also an example with storeprocedure imputs would be nice),
would be really nice. then I can learn from that example. I found it
hard to find any examples that showed me exactly this.

Thanx in advance
Sep 12 '06 #4
oh I got it! took all night but I figure it out on my own.

thanx for your help anyway, appreciate it greatly.
rowe_newsgroups wrote:
Try this for the data adapter code. -- Not tested

(I would add the below imports statement)
Imports System.Data.Ole Db

' Instantiate the DataAdapter and supply it the target
' stored procedure name and your connection variable
Dim DataAdapter as New OleDbDataAdapte r("stoCustomer" ,
OleDbConnection 1)
' Add the new parameter's name, type, and size
DataAdapter.Sel ectCommand.Para meters.Add("@Cu stName",
OleDbType.VarCh ar, 50)
' Assign the new parameter a value
DataAdapter.Sel ectCommand.Para meters("@CustNa me").Value = "Maria
Anders"

You should be ok to fill your datatable from there. If not please post
back.

Thanks,

Seth Rowe

Bonzol wrote:
Thanx for your reply

Yeah I think I need some help. I had a look, but im only a beginner.

My connection string is

Me.OleDbConnect ion1 = New System.Data.Ole Db.OleDbConnect ion
Me.OleDbConnect ion1.Connection String = "Integrated
Security=SSPI;P acket Size=4096;Data Source=""PIGMAN IA"";Tag with " & _
"column collation when possible=False; Initial
Catalog=Northwi nd;Use Procedure fo" & _
"r Prepare=1;Auto Translate=True; Persist Security
Info=False;Prov ider=""SQLOLEDB .1" & _
""";Worksta tion ID=ASPNET;Use Encryption for Data=False"

that works.

Just showing me how to use that to call a storedprocedure to fill a
datatable(also an example with storeprocedure imputs would be nice),
would be really nice. then I can learn from that example. I found it
hard to find any examples that showed me exactly this.

Thanx in advance
Sep 12 '06 #5
oh wait

now im trying some other things

Dim stringtoreturn As System.Data.Dat aTable
' Try
Me.SqlConnectio n1.Open()
Me.SqlSelectCom mand1.CommandTe xt = "[CustOrdersOrder s]"
Me.SqlSelectCom mand1.Parameter s("@CustomerID" ).Value = "VINET"
Me.SqlSelectCom mand1.ExecuteNo nQuery()
Me.SqlDataAdapt er1 = New
System.Data.Sql Client.SqlDataA dapter(Me.SqlSe lectCommand1.Co mmandText,
Me.SqlConnectio n1)
Dim dt As System.Data.Dat aTable
dt = New System.Data.Dat aTable
Me.SqlDataAdapt er1.Fill(dt)

Me.SqlConnectio n1.Close()
stringtoreturn = dt
'Catch

'End Try
Return stringtoreturn

I seem unable to send anything to the stored procedure

error I get is this

{"An SqlParameter with ParameterName '@CustomerID' is not contained by
this SqlParameterCol lection."}

the stored procedure defiantly needs that @customerID

Sep 12 '06 #6
Looks like you forgot to add the parameter first. Try changing this:
Me.SqlSelectCom mand1.CommandTe xt = "[CustOrdersOrder s]"
Me.SqlSelectCom mand1.Parameter s("@CustomerID" ).Value = "VINET"
Me.SqlSelectCom mand1.ExecuteNo nQuery()
to this: (Note, I'm not sure of the type for the parameter.)

Me.SqlSelectCom mand1.CommandTe xt = "[CustOrdersOrder s]"
--- Me.SqlSelectCom mand1.Parameter s.Add("@Custome rID", BigInt)
Me.SqlSelectCom mand1.Parameter s("@CustomerID" ).Value = "VINET"
Me.SqlSelectCom mand1.ExecuteNo nQuery()

Have Fun!

Seth Rowe

Bonzol wrote:
oh wait

now im trying some other things

Dim stringtoreturn As System.Data.Dat aTable
' Try
Me.SqlConnectio n1.Open()
Me.SqlSelectCom mand1.CommandTe xt = "[CustOrdersOrder s]"
Me.SqlSelectCom mand1.Parameter s("@CustomerID" ).Value = "VINET"
Me.SqlSelectCom mand1.ExecuteNo nQuery()
Me.SqlDataAdapt er1 = New
System.Data.Sql Client.SqlDataA dapter(Me.SqlSe lectCommand1.Co mmandText,
Me.SqlConnectio n1)
Dim dt As System.Data.Dat aTable
dt = New System.Data.Dat aTable
Me.SqlDataAdapt er1.Fill(dt)

Me.SqlConnectio n1.Close()
stringtoreturn = dt
'Catch

'End Try
Return stringtoreturn

I seem unable to send anything to the stored procedure

error I get is this

{"An SqlParameter with ParameterName '@CustomerID' is not contained by
this SqlParameterCol lection."}

the stored procedure defiantly needs that @customerID
Sep 12 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
10758
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures execute in the database server with better performance? Please advise good references for Oracle stored procedures also. thanks!!
2
2821
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the code in stored procedures (im advocating encryption of them). When deploying an application however stored procedure seem to add another level of complexity to installation. In future we also plan to have an basic ASP app with some of the...
2
9245
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
5
3398
by: Rhino | last post by:
I am trying to determine the behaviour of stored procedures in DB2 V8.2.x in Windows/Unix/Linux and how I can control that behaviour. Some documentation in the manuals is confusing the issue somewhat. First, am I right in understanding that the normal behaviour of a stored procedure, fenced or unfenced, is to only go into memory when it is invoked and to be swapped out of memory when it is not needed any more? Second, am I right in...
5
3486
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored Procedures. I thought stored pricedures were an Oracle/MS SQL Server thing and don't know how they work with Access Jet. I've looked at some of the help on stored procedures in A2003, but really don't understand what's going on. Can someone...
2
3335
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have several stored procedures to Insert and update datas in our SQL database. Some stored procedures are smaller (insert datas in only one table) and some of them are quite big (insert datas in several
0
2655
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how to call them from an ASP.Net page Every modern database system has a stored procedure language. SQL Server is no different and has a relatively sophisticated and easy to use system. This article will not attempt to go into depth in explaining...
45
3415
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
28
72559
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test Environments. What is the purpose of a view if I can just copy the vode from a view and put it into a stored procedure? Should I be accessing views from stored procedures?
11
3445
by: peter | last post by:
I am trying to get a SQL stored procedure to use user maintained MQT implicitly which raises questions on when they are used or not used. In theory you would expect the stored procedure to pick up the MQT at the time it is bound on the creation of the static SQL. This raises the question on how you stop it or start it using a MQT as there is no option on the bind. What happens when it is rebound? What happens if the plan is made invalid...
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5399
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.