Error with "Withevents"

  • I get the following error and I am not sure how to correct it. In MSDN forums they asked to include a withevents but I am not sure how I should do it. Please help me.

    Handles clause requires a WithEvents variable defined in the containing type or one of its base types

    Snippet of code:

    Imports System.Data

    Imports System.Data.SqlClient

    Public Class _Default

    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim cmd As SqlCommand

    Dim con As New SqlConnection

    Dim clientid As Integer

    Dim atuid As SqlParameter

  • That ASP.Net? You may get better answers on an ASP.Net forum. Try the ones at Microsoft.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • My data is not getting updated anyone knows why? I have posted the code below.

    USE [ATUDatabase]

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    -- =============================================

    -- Author:<Author,,Name>

    -- Create date: <Create Date,,>

    -- Description:<Description,,>

    -- =============================================

    CREATE PROCEDURE [dbo].[update]

    -- Add the parameters for the stored procedure here

    @Referral_Method varchar(700),

    @Referral_Source varchar(700),

    @Original_Referral_Date varchar(700),

    @Current_Referral_Date varchar(700),

    @Primaryagency_Name varchar(700),

    @Primaryagency_Contact varchar(700),

    @Primaryagency_Address varchar(700),

    @Primaryagency_City varchar(700),

    @Primaryagency_State varchar(700),

    @Primaryagency_Zip varchar(700),

    @Primaryagency_Disnum varchar(700),

    @Primaryagency_num varchar(700),

    @Primaryagency_Fax varchar(700),

    @Primaryagency_email varchar(700),

    @Primaryagency_TTY varchar(700)

    AS

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

    Declare @scope_Id int

    SET @scope_Id = SCOPE_IDENTITY()

    -- Insert statements for procedure here

    UPDATE [dbo].[ATU Clients]

    SET[Referral_Method] = @Referral_Method,

    [Referral_Source] = @Referral_Source,

    [Original_Referral_Date] = @Original_Referral_Date,

    [Current_Referral_Date] = @Current_Referral_Date,

    [Primary_(PAS)_Agency_Name] = @Primaryagency_Name,

    [Primary_Agency_Address] = @Primaryagency_Address,

    [Primary_Agency_City] = @Primaryagency_City,

    [Primary_Agency_State] = @Primaryagency_State,

    [Primary_Agency_Zip_Code] = @Primaryagency_Zip,

    [Primary_Agency_District#] = @Primaryagency_Disnum,

    [Primary_Agency#] = @Primaryagency_num,

    [Primary_Agency_Fax#] = @Primaryagency_Fax,

    [Primary_Agency_E-Mail] = @Primaryagency_email

    WHERE (ATU_ID = @scope_id);

    SELECT * FROM [ATU Clients]

    END

    GO

  • Because @scope_Id is null. I assume you are calling this from your page which means the connection is new and therefore scope_identity() is null.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • And why are all your variables varchar(700)?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Yeah I changed it to 50 yesterday but I posted the previous code. WHat should I do to see the result? I need to enter it into the last row.

  • Not a lot of detail to go on but...

    I assume you enter this record and then update it? Get the identity when you insert and pass it to your update proc. The way you coded that update is very prone to error because it assumes that scope_identity is not null. In other words, you can't run that proc by itself unless certain other conditions have been met. Not a good strategy.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply