473,466 Members | 1,394 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with Code to Execute a Stored Procedure

I am trying to Execute a simple Stored Procedure using
ASP/VB. I have spent numerous hours with this,
researching
books and looking on the internet. I can't get a direct
answer. THis is my program, followed by the errors, Can
anyone Please Help, Please, Please, Please.

Sub cmdGO_Click(sender As Object, e As EventArgs)
DataGrid1.DataSource = GetResults(TxtSort.Text)
DataGrid1.DataBind()
End Sub
Function GetResults(ByVal txtSort As String) As
System.Data.DataSet
Dim connectionString As String
= "server='(local)'; user id='sa'; password='fritz';
database='Cutis'"
Dim dbConnection As System.Data.IDbConnection =
New System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim cmdGO As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand "EMSTONY",
(connectionString)
cmdGO.CommandText = queryString
cmdGO.CommandType = CommandType.StoredProcedure

Dim dbParam_txtSort As System.Data.IDataParameter
= New System.Data.SqlClient.SqlParameter
dbParam_txtSort.ParameterName = "@TxtSort"
dbParam_txtSort.Value = txtSort
dbParam_txtSort.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_txtSort)

Dim dataAdapter As System.Data.IDbDataAdapter =
New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function

ERRORS:

:\BegASPNET11\Ch04\Baldwin20.aspx(18) : error BC30205:
End
of statement expected.

Dim cmdGO As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand "EMSTONY",
(connectionString)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(19) : error
BC30456: 'CommandText' is not a member
of 'System.Web.UI.WebControls.Button'.

cmdGO.CommandText = queryString
~~~~~~~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(19) : error BC30451:
Name 'queryString' is not declared.

cmdGO.CommandText = queryString
~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(20) : error
BC30456: 'CommandType' is not a member
of 'System.Web.UI.WebControls.Button'.

cmdGO.CommandType =
CommandType.StoredProcedure

~~~~~~~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(20) : error BC30451:
Name 'CommandType' is not declared.

cmdGO.CommandType =
CommandType.StoredProcedure

~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(26) : error BC30451:
Name 'dbCommand' is not declared.

dbCommand.Parameters.Add(dbParam_txtSort)
~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(29) : error BC30451:
Name 'dbCommand' is not declared.

dataAdapter.SelectCommand = dbCommand
~~~~~~~~~
..
Nov 19 '05 #1
2 3453
1. If the wraps exist in your file, and are not an artifact of posting, you
need the continue line character (underscore = _) on the first line

2. It is easier, for me, to code like so:

'NOTE: Items in {} are items you need to fill in
Dim connString As String = "{Your Conn String Here}"
Dim sproc As String = "{sproc name here}"
Dim paramSize as Int = {size of varchar here}

Dim conn As New SqlConnection(connString)
Dim cmd As New SqlCommand(sproc)
cmd.CommandType = CommandType.StoredProcedure

'Explicitly create (this is a simpler overload)
Dim param as New SqlParameter("@txtSort", DbType.String, paramSize)
param.Value = txtSort.Text

cmd.Parameters.Add(param)

Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet("{NameOfDataSet}")

da.TableMappings.Add("Table", "{FriendlyResultTableName}")

Try
conn.Open()
da.Fill(ds)
Catch ex As Exception
'Error handling here
Finally
If (conn.State = ConnectionState.Open) Then
conn.Close()
End If

conn.Dispose()
End Try

Return ds
That should give you some ideas, at least

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Jeff Thur" wrote:
I am trying to Execute a simple Stored Procedure using
ASP/VB. I have spent numerous hours with this,
researching
books and looking on the internet. I can't get a direct
answer. THis is my program, followed by the errors, Can
anyone Please Help, Please, Please, Please.

Sub cmdGO_Click(sender As Object, e As EventArgs)
DataGrid1.DataSource = GetResults(TxtSort.Text)
DataGrid1.DataBind()
End Sub
Function GetResults(ByVal txtSort As String) As
System.Data.DataSet
Dim connectionString As String
= "server='(local)'; user id='sa'; password='fritz';
database='Cutis'"
Dim dbConnection As System.Data.IDbConnection =
New System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim cmdGO As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand "EMSTONY",
(connectionString)
cmdGO.CommandText = queryString
cmdGO.CommandType = CommandType.StoredProcedure

Dim dbParam_txtSort As System.Data.IDataParameter
= New System.Data.SqlClient.SqlParameter
dbParam_txtSort.ParameterName = "@TxtSort"
dbParam_txtSort.Value = txtSort
dbParam_txtSort.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_txtSort)

Dim dataAdapter As System.Data.IDbDataAdapter =
New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function

ERRORS:

:\BegASPNET11\Ch04\Baldwin20.aspx(18) : error BC30205:
End
of statement expected.

Dim cmdGO As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand "EMSTONY",
(connectionString)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(19) : error
BC30456: 'CommandText' is not a member
of 'System.Web.UI.WebControls.Button'.

cmdGO.CommandText = queryString
~~~~~~~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(19) : error BC30451:
Name 'queryString' is not declared.

cmdGO.CommandText = queryString
~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(20) : error
BC30456: 'CommandType' is not a member
of 'System.Web.UI.WebControls.Button'.

cmdGO.CommandType =
CommandType.StoredProcedure

~~~~~~~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(20) : error BC30451:
Name 'CommandType' is not declared.

cmdGO.CommandType =
CommandType.StoredProcedure

~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(26) : error BC30451:
Name 'dbCommand' is not declared.

dbCommand.Parameters.Add(dbParam_txtSort)
~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(29) : error BC30451:
Name 'dbCommand' is not declared.

dataAdapter.SelectCommand = dbCommand
~~~~~~~~~
..

Nov 19 '05 #2
-----Original Message-----
1. If the wraps exist in your file, and are not an artifact of posting, youneed the continue line character (underscore = _) on the first line
2. It is easier, for me, to code like so:

'NOTE: Items in {} are items you need to fill in
Dim connString As String = "{Your Conn String Here}"
Dim sproc As String = "{sproc name here}"
Dim paramSize as Int = {size of varchar here}

Dim conn As New SqlConnection(connString)
Dim cmd As New SqlCommand(sproc)
cmd.CommandType = CommandType.StoredProcedure

'Explicitly create (this is a simpler overload)
Dim param as New SqlParameter("@txtSort", DbType.String, paramSize)param.Value = txtSort.Text

cmd.Parameters.Add(param)

Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet("{NameOfDataSet}")

da.TableMappings.Add ("Table", "{FriendlyResultTableName}")
Try
conn.Open()
da.Fill(ds)
Catch ex As Exception
'Error handling here
Finally
If (conn.State = ConnectionState.Open) Then
conn.Close()
End If

conn.Dispose()
End Try

Return ds
That should give you some ideas, at least

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

"Jeff Thur" wrote:
I am trying to Execute a simple Stored Procedure using
ASP/VB. I have spent numerous hours with this,
researching
books and looking on the internet. I can't get a direct answer. THis is my program, followed by the errors, Can anyone Please Help, Please, Please, Please.

Sub cmdGO_Click(sender As Object, e As EventArgs)
DataGrid1.DataSource = GetResults(TxtSort.Text)
DataGrid1.DataBind()
End Sub
Function GetResults(ByVal txtSort As String) As
System.Data.DataSet
Dim connectionString As String
= "server='(local)'; user id='sa'; password='fritz';
database='Cutis'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection (connectionString)

Dim cmdGO As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand "EMSTONY",
(connectionString)
cmdGO.CommandText = queryString
cmdGO.CommandType = CommandType.StoredProcedure

Dim dbParam_txtSort As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_txtSort.ParameterName = "@TxtSort"
dbParam_txtSort.Value = txtSort
dbParam_txtSort.DbType = System.Data.DbType.String dbCommand.Parameters.Add(dbParam_txtSort)

Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function

ERRORS:

:\BegASPNET11\Ch04\Baldwin20.aspx(18) : error BC30205:
End
of statement expected.

Dim cmdGO As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand "EMSTONY",
(connectionString)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C:\BegASPNET11\Ch04\Baldwin20.aspx(19) : error
BC30456: 'CommandText' is not a member
of 'System.Web.UI.WebControls.Button'.

cmdGO.CommandText = queryString
~~~~~~~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(19) : error BC30451: Name 'queryString' is not declared.

cmdGO.CommandText = queryString
~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(20) : error
BC30456: 'CommandType' is not a member
of 'System.Web.UI.WebControls.Button'.

cmdGO.CommandType =
CommandType.StoredProcedure

~~~~~~~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(20) : error BC30451: Name 'CommandType' is not declared.

cmdGO.CommandType =
CommandType.StoredProcedure

~~~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(26) : error BC30451: Name 'dbCommand' is not declared.

dbCommand.Parameters.Add(dbParam_txtSort)
~~~~~~~~~
C:\BegASPNET11\Ch04\Baldwin20.aspx(29) : error BC30451: Name 'dbCommand' is not declared.

dataAdapter.SelectCommand = dbCommand
~~~~~~~~~
..
Why do I get this error, I'm totally Confused here.

.


I have followed your Code But No Luck. Error on this
Statement.

cmd.CommandType = CommandType.StoredProcedure
BC30188 DECLARATION EXPECTED.
Nov 19 '05 #3

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

Similar topics

1
by: godwin | last post by:
Hi, I would like to execute an oracle stored procedure using the any oracle database module which satisfies the Database Specification standard. I have tried cxOracle and Odbc database packages...
2
by: Matt | last post by:
I want to exexute stored procedure in ASP, but it has error "Microsoft VBScript compilation (0x800A0401) Expected end of statement" on line (1). The stored procedure "sp_emp" contain "select *...
4
by: TJS | last post by:
trying to get a record count from a stored procedure using a supplied SQL statement Error msg: =========== "The SqlParameterCollection only accepts non-null SqlParameter type objects,not...
3
by: Russell Verdun | last post by:
From a vb.net application I'm want to execute an Oracle Stored Procedure via a web service. What would be the best way to approach this? I can't pass and Oracle Command or the parameter objects...
4
by: Magy | last post by:
What would be the best way to execute a Oracle stored procedure that excepts several input paramters, through a web method in vb.net. What would be a good way to get to the web method, the Oracle...
1
by: RSH | last post by:
Im trying to create a stored procedure of the following code. I want to set it so that I have to send the first 4 variables (@DB, @BackUpFile,@TestDB,@RestoreFile). I am having trouble when i try...
6
by: rn5a | last post by:
In a shopping cart app, when a user finalizes his order, records from a temporary table named 'TempCart' get inserted into another table name 'Orders' after which the records from 'TempCart' are...
2
by: gayano | last post by:
Hi all, I need help with Sql Stored Procedure, I have two fields in a table Table named "User" Field1 named "FirstName" Field2 named "LastName" I need to give a chance to user to search...
4
by: aCe | last post by:
hi all, i need to convert these simple PHP code into stored procedure : <?php $result = mssql_query( "SELECT whid, whcode FROM warehouse" ); while( $wh = mssql_fetch_object( $result ) ) {...
1
by: visweswaran2830 | last post by:
Hi, I am using SQuirrel. Now I want to execute stored procedure in SQuirrel. How can I achieve this. Thanks in Advance
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.