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 February 17th, 2006, 11:50 AM
Registered User
 
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with using a StoredProcedure to write to SQL

Hello, I’m very new to this so I’m probably doing something very stupid!

I’m just trying to save the contents of three fields to an SQL database using a stored procedure.

I’ve written the following code that doesn’t work.
Is it complete rubbish or am I almost there?

Please help…

Thanks,


Imports System.Data
Imports System.Data.SqlClient

Partial Class deleteEvent
    'Inherits System.Web.UI.Page
    Inherits spc_masterclass

    Private Sub deleteEvent(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Selectid.Click
        Dim DS As DataSet
        Dim MyConnection As SqlConnection
        Dim MyDataAdapter As SqlDataAdapter
        Dim intEventID As String
        Dim dteUpdatedOn As String = Date.Now
        Dim txtUpdatedBy As String = "garrygri"

        intEventID = ddl_Event.SelectedValue
        dteUpdatedOn = dteUpdatedOn.Substring(0, 10)

        If Page.IsValid = True Then
            EventID.Text = intEventID
            UpdatedOn.Text = dteUpdatedOn
            UpdatedBy.Text = txtUpdatedBy

            'Create a connection to the SQL Server
            MyConnection = New SqlConnection("Data Source=160.160.10.14;Initial Catalog=CAT_SYSTEM;Persist Security Info=True;User ID=test;Password=test;Pooling=False")
            MyDataAdapter = New SqlDataAdapter("sp_deleteEvent", MyConnection)
            MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure

            'Create the storedProcedure parameters
            MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@eventID", SqlDbType.SmallInt))
            MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@UpdatedOn", SqlDbType.SmallDateTime))
            MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@UpdatedBy", SqlDbType.NVarChar, 15))

            'Assign a value to the parameters
            MyDataAdapter.SelectCommand.Parameters("@eventID") .Value = EventID.Text
            MyDataAdapter.SelectCommand.Parameters("@UpdatedOn ").Value = UpdatedOn.Text
            MyDataAdapter.SelectCommand.Parameters("@UpdatedBy ").Value = UpdatedBy.Text

            DS = New DataSet()
            MyDataAdapter.Fill(DS, "sp_deleteEvent")

            MyDataAdapter.Dispose()
            MyConnection.Close()

            'display temporary test text
            EventID.Visible = True
            UpdatedOn.Visible = True
            UpdatedBy.Visible = True

        End If
    End Sub
End Class
 
Old February 17th, 2006, 03:42 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

You are doing a Select, I don't see code for an Update.

Jim






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with StoredProcedure tmadhavi SQL Server 2000 1 December 26th, 2007 12:41 PM
StoredProcedure For Adding PlayList tmadhavi SQL Server 2000 0 December 20th, 2007 08:31 AM
SQL Server StoredProcedure Parameter pass erictamlam C# 2005 3 March 27th, 2007 01:31 AM
Calling a Storedprocedure from ASP arnniema Classic ASP Basics 1 September 15th, 2005 07:49 AM
StoredProcedure NiNe ADO.NET 1 March 1st, 2004 07:22 AM





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