473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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.OleDb.OleDbDataAdapter
dataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQL,
Me.OleDbConnection1)
Try
Dim dt As System.Data.DataTable
dt = New System.Data.DataTable
dataAdapter.Fill(dt)
If dt.Rows.Count 0 Then
If dt.Rows(0).ItemArray.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 3403
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.OleDb.OleDbDataAdapter
dataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQL,
Me.OleDbConnection1)
Try
Dim dt As System.Data.DataTable
dt = New System.Data.DataTable
dataAdapter.Fill(dt)
If dt.Rows.Count 0 Then
If dt.Rows(0).ItemArray.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.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbConnection1.ConnectionString = "Integrated
Security=SSPI;Packet Size=4096;Data Source=""PIGMANIA"";Tag with " & _
"column collation when possible=False;Initial
Catalog=Northwind;Use Procedure fo" & _
"r Prepare=1;Auto Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1" & _
""";Workstation 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.OleDb

' Instantiate the DataAdapter and supply it the target
' stored procedure name and your connection variable
Dim DataAdapter as New OleDbDataAdapter("stoCustomer",
OleDbConnection1)
' Add the new parameter's name, type, and size
DataAdapter.SelectCommand.Parameters.Add("@CustNam e",
OleDbType.VarChar, 50)
' Assign the new parameter a value
DataAdapter.SelectCommand.Parameters("@CustName"). 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.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbConnection1.ConnectionString = "Integrated
Security=SSPI;Packet Size=4096;Data Source=""PIGMANIA"";Tag with " & _
"column collation when possible=False;Initial
Catalog=Northwind;Use Procedure fo" & _
"r Prepare=1;Auto Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1" & _
""";Workstation 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.OleDb

' Instantiate the DataAdapter and supply it the target
' stored procedure name and your connection variable
Dim DataAdapter as New OleDbDataAdapter("stoCustomer",
OleDbConnection1)
' Add the new parameter's name, type, and size
DataAdapter.SelectCommand.Parameters.Add("@CustNam e",
OleDbType.VarChar, 50)
' Assign the new parameter a value
DataAdapter.SelectCommand.Parameters("@CustName"). 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.OleDbConnection1 = New System.Data.OleDb.OleDbConnection
Me.OleDbConnection1.ConnectionString = "Integrated
Security=SSPI;Packet Size=4096;Data Source=""PIGMANIA"";Tag with " & _
"column collation when possible=False;Initial
Catalog=Northwind;Use Procedure fo" & _
"r Prepare=1;Auto Translate=True;Persist Security
Info=False;Provider=""SQLOLEDB.1" & _
""";Workstation 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.DataTable
' Try
Me.SqlConnection1.Open()
Me.SqlSelectCommand1.CommandText = "[CustOrdersOrders]"
Me.SqlSelectCommand1.Parameters("@CustomerID").Val ue = "VINET"
Me.SqlSelectCommand1.ExecuteNonQuery()
Me.SqlDataAdapter1 = New
System.Data.SqlClient.SqlDataAdapter(Me.SqlSelectC ommand1.CommandText,
Me.SqlConnection1)
Dim dt As System.Data.DataTable
dt = New System.Data.DataTable
Me.SqlDataAdapter1.Fill(dt)

Me.SqlConnection1.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 SqlParameterCollection."}

the stored procedure defiantly needs that @customerID

Sep 12 '06 #6
Looks like you forgot to add the parameter first. Try changing this:
Me.SqlSelectCommand1.CommandText = "[CustOrdersOrders]"
Me.SqlSelectCommand1.Parameters("@CustomerID").Val ue = "VINET"
Me.SqlSelectCommand1.ExecuteNonQuery()
to this: (Note, I'm not sure of the type for the parameter.)

Me.SqlSelectCommand1.CommandText = "[CustOrdersOrders]"
--- Me.SqlSelectCommand1.Parameters.Add("@CustomerID", BigInt)
Me.SqlSelectCommand1.Parameters("@CustomerID").Val ue = "VINET"
Me.SqlSelectCommand1.ExecuteNonQuery()

Have Fun!

Seth Rowe

Bonzol wrote:
oh wait

now im trying some other things

Dim stringtoreturn As System.Data.DataTable
' Try
Me.SqlConnection1.Open()
Me.SqlSelectCommand1.CommandText = "[CustOrdersOrders]"
Me.SqlSelectCommand1.Parameters("@CustomerID").Val ue = "VINET"
Me.SqlSelectCommand1.ExecuteNonQuery()
Me.SqlDataAdapter1 = New
System.Data.SqlClient.SqlDataAdapter(Me.SqlSelectC ommand1.CommandText,
Me.SqlConnection1)
Dim dt As System.Data.DataTable
dt = New System.Data.DataTable
Me.SqlDataAdapter1.Fill(dt)

Me.SqlConnection1.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 SqlParameterCollection."}

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
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...
2
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...
2
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...
5
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...
5
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...
2
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...
0
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...
45
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
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...
11
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.