Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 1st, 2006, 06:59 AM
Registered User
 
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Some basic advice on updating SQL please!

Hello, I hope someone could help me out here,

I have the following stored procedure in an SQL server database:

CREATE PROCEDURE sp_deleteEvent (
@eventID SmallInt,
@lastUpdatedOn SmallDateTime,
@lastUpdatedBy nVarChar(15)
)
AS
begin
    update event
    set
       lastUpdateOn=@lastUpdatedOn,
       lastUpdateBy= @lastUpdatedBy,
       rowStatus= 0
    where eventID = @eventID
end
GO

I want to pass the three parameters @eventID, @lastUpdatedOn and @lastUpdatedBy to it from a vb.net script that is attached as ‘code behind’ from an ASP.net page.

Just now my VB script simply shows the required data on screen for testing:

Imports System.Data
Imports System.Data.SqlClient
Partial Class deleteEvent
    Inherits spc_masterclass
    Private Sub deleteEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Selectid.Click
        Dim intEventID As String
        Dim dteUpdatedOn As String = Date.Now
        Dim txtUpdatedBy As String = "testusr"
        intEventID = ddl_Event.SelectedValue
        dteUpdatedOn = dteUpdatedOn.Substring(0, 10)
        If Page.IsValid = True Then
            EventID.Text = intEventID
            UpdatedOn.Text = dteUpdatedOn
        UpdatedBy.Text = txtUpdatedBy
            'display temporary test text
            EventID.Visible = True
            UpdatedOn.Visible = True
            UpdatedBy.Visible = True
        End If
    End Sub
End Class

The ASP simply asked the user to select an item from a list:
The VB then finds the values that are required to be sent to the stored procedure.
Unfortunately I have no idea how to do this!
Is this a simple thing?
I would appreciate it if somebody could help out or point me at some tutorials explaining how to do this…


Thanks.
 
Old March 1st, 2006, 02:24 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Look into the sqlcommand object or sqldataadapter object. Then use ExecuteNonQuery()

Jim

 
Old March 2nd, 2006, 10:58 AM
Registered User
 
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, I managed to get this to work by using the following...

        If Page.IsValid = True Then
            'display temporary test text
            EventID.Text = intEventID
            UpdatedOn.Text = dteUpdatedOn
            UpdatedBy.Text = txtUpdatedBy
            EventID.Visible = True
            UpdatedOn.Visible = True
            UpdatedBy.Visible = True

            'Create a connection to the SQL Server and run the stored procedure
            Dim sql As String = "exec sp_deleteEvent @eventID, @UpdatedOn, @UpdatedBy "
            MyConnection = New SqlConnection("Data Source=160.160.10.14;Initial Catalog=CAT_SYSTEM;Persist Security Info=True;User ID=test;Password=test;Pooling=False")
            Dim myCommand As New SqlCommand(sql, MyConnection)
            myCommand.Parameters.Add(New SqlParameter("@eventID", intEventID))
            myCommand.Parameters.Add(New SqlParameter("@UpdatedOn", dteUpdatedOn))
            myCommand.Parameters.Add(New SqlParameter("@UpdatedBy", txtUpdatedBy))
            MyConnection.Open()
            myCommand.ExecuteNonQuery()
            myCommand.Dispose()
            MyConnection.Close()
        End If

But I was looking for a way to pass paramiters directly to the stored procedure rather than running it from an SQL script!

Thanks for the reply though!
 
Old March 2nd, 2006, 02:52 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Quote:
quote:
But I was looking for a way to pass paramiters directly to the stored procedure rather than running it from an SQL script!
Not sure what you mean by that statement..

You are not running a sql script, you are using the .NET framework to call a SP. There is no shorter way, if that is what you mean.







Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server Advice Wanted kwilliams SQL Server 2000 1 June 27th, 2006 03:47 PM
Basic SQL Problem mattastic SQL Server 2000 4 December 8th, 2004 05:20 AM
SQL and Visual Basic mytreasure23 SQL Server 2000 1 November 9th, 2004 03:26 AM
Visual Basic code for Updating (Editing) DataSet11 connijean VB Databases Basics 0 May 5th, 2004 05:53 PM
Still needs advice on “Upload MSDE to SQL Server Jan_Ma SQL Server 2000 5 June 23rd, 2003 07:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.