Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 May 23rd, 2004, 08:09 PM
Authorized User
Join Date: Apr 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help! No idea what the problem is.



I'm stumped. I'm developing a page that lets participants in a program edit their info. Textboxes are filled with participant info on page load and three buttons on the bottom of the page let them edit their info: edit, update, and cancel. I'd really appreciate it if some helpful folks would look at my code below and help me figure out what I'm doing wrong.

This is the code behind file...

Imports System.Data.SqlClient

Public MustInherit Class ParticipantDetailsEdit
    Inherits System.Web.UI.UserControl
    Protected WithEvents txtFirstName As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtLastName As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtLocalAddress1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtLocalAddress2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtLocalCity As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtLocalState As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtLocalZip As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPermZip As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPermState As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPermCity As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPermAddress2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPermAddress1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPhone1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPhone2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtEmail As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtBestTime As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtFundraisingGoal As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtProfile As System.Web.UI.WebControls.TextBox
    Protected WithEvents btnRemove As System.Web.UI.WebControls.Button
    Protected WithEvents btnEdit As System.Web.UI.WebControls.Button
    Protected WithEvents btnUpdate As System.Web.UI.WebControls.Button
    Protected WithEvents btnCancel As System.Web.UI.WebControls.Button
    Protected WithEvents lblParticipantId As System.Web.UI.WebControls.Label
    Protected WithEvents lblErrorMsg As System.Web.UI.WebControls.Label

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
        End If
    End Sub

    Private Sub LoadParticipantDetails()
        Dim participant As New ParticipantAdmin
        Dim participantDetails As ParticipantDetails
        Dim participantId As String = Convert.ToInt32(Context.Session("LaPazInternationa l_ParticipantID"))

        participantDetails = participant.GetParticipantDetails(participantId)
        lblParticipantId.Text = participantId
        txtFirstName.Text = participantDetails.FirstName
        txtLastName.Text = participantDetails.LastName
        txtEmail.Text = participantDetails.Email
        txtPhone1.Text = participantDetails.Phone1
        txtPhone2.Text = participantDetails.Phone2
        txtBestTime.Text = participantDetails.BestTime
        txtLocalAddress1.Text = participantDetails.LocalAddress1
        txtLocalAddress2.Text = participantDetails.LocalAddress2
        txtLocalCity.Text = participantDetails.LocalCity
        txtLocalState.Text = participantDetails.LocalState
        txtLocalZip.Text = participantDetails.LocalZip
        txtPermAddress1.Text = participantDetails.PermAddress1
        txtPermAddress2.Text = participantDetails.PermAddress2
        txtPermCity.Text = participantDetails.PermCity
        txtPermState.Text = participantDetails.PermState
        txtPermZip.Text = participantDetails.PermZip
        txtFundraisingGoal.Text = participantDetails.FundraisingGoal
        txtProfile.Text = participantDetails.Profile

        btnEdit.Enabled = True
        btnUpdate.Enabled = False
        btnCancel.Enabled = False
    End Sub

    Private Sub SetEditMode(ByVal value As Boolean)
        txtFirstName.Enabled = value
        txtLastName.Enabled = value
        txtEmail.Enabled = value
        txtPhone1.Enabled = value
        txtPhone2.Enabled = value
        txtBestTime.Enabled = value
        txtLocalAddress1.Enabled = value
        txtLocalAddress2.Enabled = value
        txtLocalCity.Enabled = value
        txtLocalState.Enabled = value
        txtLocalZip.Enabled = value
        txtPermAddress1.Enabled = value
        txtPermAddress2.Enabled = value
        txtPermCity.Enabled = value
        txtPermState.Enabled = value
        txtPermZip.Enabled = value
        txtFundraisingGoal.Enabled = value
        txtProfile.Enabled = value

        btnEdit.Enabled = Not value
        btnUpdate.Enabled = value
        btnCancel.Enabled = value
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim participantDetails As New ParticipantDetails
        participantDetails.ParticipantId = lblParticipantId.Text
        participantDetails.FirstName = txtFirstName.Text
        participantDetails.LastName = txtLastName.Text
        participantDetails.Email = txtEmail.Text
        participantDetails.Phone1 = txtPhone1.Text
        participantDetails.Phone2 = txtPhone2.Text
        participantDetails.BestTime = txtBestTime.Text
        participantDetails.LocalAddress1 = txtLocalAddress1.Text
        participantDetails.LocalAddress2 = txtLocalAddress2.Text
        participantDetails.LocalCity = txtLocalCity.Text
        participantDetails.LocalState = txtLocalState.Text
        participantDetails.LocalZip = txtLocalZip.Text
        participantDetails.PermAddress1 = txtPermAddress1.Text
        participantDetails.PermAddress2 = txtPermAddress2.Text
        participantDetails.PermCity = txtPermCity.Text
        participantDetails.PermState = txtPermState.Text
        participantDetails.PermZip = txtPermZip.Text
        participantDetails.FundraisingGoal = txtFundraisingGoal.Text
        participantDetails.Profile = txtProfile.Text

            Dim participant As New ParticipantAdmin
            participant.UpdateParticipantDetails(participantDe tails)
            lblErrorMsg.Text = "Could not make the update. Please contact the site administrator"
        End Try

    End Sub
End Class

This is the vb file...

Imports System.Data.SqlClient

Public Class ParticipantDetails
    Public ParticipantId As String
    Public FirstName As String
    Public LastName As String
    Public Email As String
    Public Phone1 As String
    Public Phone2 As String
    Public BestTime As String
    Public LocalAddress1 As String
    Public LocalAddress2 As String
    Public LocalCity As String
    Public LocalState As String
    Public LocalZip As String
    Public PermAddress1 As String
    Public PermAddress2 As String
    Public PermCity As String
    Public PermState As String
    Public PermZip As String
    Public Speaking As String
    Public ReadingWriting As String
    Public InterviewNotes As String
    Public FundraisingGoal As String
    Public Profile As String
End Class

Public Class ParticipantAdmin
Public Function GetParticipantDetails(ByVal participantId As String) As ParticipantDetails
        Dim connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand("GetParticipantDetails", connection)
        command.CommandType = CommandType.StoredProcedure

        command.Parameters.Add("@ParticipantID", SqlDbType.Int)
        command.Parameters("@ParticipantID").Value = participantId

        Dim reader As SqlDataReader
        reader = command.ExecuteReader(CommandBehavior.CloseConnect ion)

        Dim participantDetails As New ParticipantDetails
        If reader.Read() Then
            participantDetails.FirstName = reader("FirstName").ToString
            participantDetails.LastName = reader("LastName").ToString
            participantDetails.Email = reader("Email").ToString
            participantDetails.Phone1 = reader("Phone1").ToString
            participantDetails.Phone2 = reader("Phone2").ToString
            participantDetails.BestTime = reader("BestTime").ToString
            participantDetails.LocalAddress1 = reader("LocalAddress1").ToString
            participantDetails.LocalAddress2 = reader("LocalAddress2").ToString
            participantDetails.LocalCity = reader("LocalCity").ToString
            participantDetails.LocalState = reader("LocalState").ToString
            participantDetails.LocalZip = reader("LocalZip").ToString
            participantDetails.PermAddress1 = reader("PermAddress1").ToString
            participantDetails.PermAddress2 = reader("PermAddress2").ToString
            participantDetails.PermCity = reader("PermCity").ToString
            participantDetails.PermState = reader("PermState").ToString
            participantDetails.PermZip = reader("PermZip").ToString
            participantDetails.Speaking = reader("Speaking").ToString
            participantDetails.ReadingWriting = reader("ReadingWriting").ToString
            participantDetails.InterviewNotes = reader("InterviewNotes").ToString
            participantDetails.FundraisingGoal = reader("FundraisingGoal").ToString
            participantDetails.Profile = reader("Profile").ToString
        End If

        Return participantDetails
    End Function

    Public Sub UpdateParticipantDetails(ByVal participantDetails As ParticipantDetails)
        Dim connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand("UpdateParticipantDetails", connection)
        command.CommandType = CommandType.StoredProcedure

        command.Parameters.Add("@ParticipantID", SqlDbType.Int)
        command.Parameters("@ParticipantID").Value = participantDetails.ParticipantId

        command.Parameters.Add("@FirstName", SqlDbType.VarChar, 50)
        command.Parameters("@FirstName").Value = participantDetails.FirstName

        command.Parameters.Add("@LastName", SqlDbType.VarChar, 50)
        command.Parameters("@LastName").Value = participantDetails.LastName

        command.Parameters.Add("@Email", SqlDbType.VarChar, 50)
        command.Parameters("@Email").Value = participantDetails.Email

        command.Parameters.Add("@Phone1", SqlDbType.VarChar, 50)
        command.Parameters("@Phone1").Value = participantDetails.Phone1

        If participantDetails.Phone2.Trim <> "" Then
            command.Parameters.Add("@Phone2", SqlDbType.VarChar, 50)
            command.Parameters("@Phone2").Value = participantDetails.Phone2
        End If

        command.Parameters.Add("@BestTime", SqlDbType.VarChar, 200)
        command.Parameters("@BestTime").Value = participantDetails.BestTime

        command.Parameters.Add("@LocalAddress1", SqlDbType.VarChar, 50)
        command.Parameters("@LocalAddress1").Value = participantDetails.LocalAddress1

        If participantDetails.LocalAddress2.Trim <> "" Then
            command.Parameters.Add("@LocalAddress2", SqlDbType.VarChar, 100)
            command.Parameters("@LocalAddress2").Value = participantDetails.LocalAddress2
        End If

        command.Parameters.Add("@LocalCity", SqlDbType.VarChar, 100)
        command.Parameters("@LocalCity").Value = participantDetails.LocalCity

        command.Parameters.Add("@LocalState", SqlDbType.VarChar, 50)
        command.Parameters("@LocalState").Value = participantDetails.LocalState

        command.Parameters.Add("@LocalZip", SqlDbType.VarChar, 50)
        command.Parameters("@LocalZip").Value = participantDetails.LocalZip

        If participantDetails.PermAddress1.Trim <> "" Then
            command.Parameters.Add("@PermAddress1", SqlDbType.VarChar, 100)
            command.Parameters("@PermAddress1").Value = participantDetails.PermAddress1
        End If

        If participantDetails.PermAddress2.Trim <> "" Then
            command.Parameters.Add("@PermAddress2", SqlDbType.VarChar, 100)
            command.Parameters("@PermAddress2").Value = participantDetails.PermAddress2
        End If

        If participantDetails.PermCity.Trim <> "" Then
            command.Parameters.Add("@PermCity", SqlDbType.VarChar, 50)
            command.Parameters("@PermCity").Value = participantDetails.PermCity
        End If

        If participantDetails.PermState.Trim <> "" Then
            command.Parameters.Add("@PermState", SqlDbType.VarChar, 50)
            command.Parameters("@PermState").Value = participantDetails.PermState
        End If

        If participantDetails.PermZip.Trim <> "" Then
            command.Parameters.Add("@PermZip", SqlDbType.VarChar, 50)
            command.Parameters("@PermZip").Value = participantDetails.PermZip
        End If

        If participantDetails.Speaking.Trim <> "" Then
            command.Parameters.Add("@Speaking", SqlDbType.VarChar, 500)
            command.Parameters("@Speaking").Value = participantDetails.Speaking
        End If

        If participantDetails.ReadingWriting.Trim <> "" Then
            command.Parameters.Add("@ReadingWriting", SqlDbType.VarChar, 500)
            command.Parameters("@ReadingWriting").Value = participantDetails.ReadingWriting
        End If

        If participantDetails.InterviewNotes.Trim <> "" Then
            command.Parameters.Add("@InterviewNotes", SqlDbType.VarChar, 8000)
            command.Parameters("@InterviewNotes").Value = participantDetails.InterviewNotes
        End If

        If participantDetails.FundraisingGoal.Trim <> "" Then
            command.Parameters.Add("@FundraisingGoal", SqlDbType.VarChar, 50)
            command.Parameters("@FundraisingGoal").Value = participantDetails.FundraisingGoal
        End If

        If participantDetails.Profile.Trim <> "" Then
            command.Parameters.Add("@Profile", SqlDbType.VarChar, 8000)
            command.Parameters("@Profile").Value = participantDetails.Profile
        End If

    End Sub
End Class

And finally the SQL code...

ALTER PROCEDURE UpdateParticipantDetails
@ParticipantID int,
@FirstName varchar(50),
@LastName varchar(50),
@Email varchar(50),
@Phone1 varchar(50),
@Phone2 varchar(50),
@BestTime varchar(50),
@LocalAddress1 varchar(50),
@LocalAddress2 varchar(50),
@LocalCity varchar(50),
@LocalState varchar(50),
@LocalZip varchar(50),
@PermAddress1 varchar(50),
@PermAddress2 varchar(50),
@PermCity varchar(50),
@PermState varchar(50),
@PermZip varchar(50),
@Speaking varchar(50),
@ReadingWriting varchar(50),
@InterviewNotes varchar(8000),
@FundraisingGoal varchar(50),
@Profile varchar(8000)

UPDATE Participant
SET FirstName = @FirstName, LastName = @LastName, Email = @Email, Phone1 = @Phone1,
Phone2 = @Phone2, BestTime = @BestTime, LocalAddress1 = @LocalAddress1, LocalAddress2 = @LocalAddress2,
LocalCity = @LocalCity, LocalState = @LocalState, LocalZip = @LocalZip,
PermAddress1 = @PermAddress1, PermAddress2 = @PermAddress2, PermCity = @PermCity,
PermState = @PermState, PermZip = @PermZip, Speaking = @Speaking, ReadingWriting = @ReadingWriting,
InterviewNotes = @InterviewNotes, FundraisingGoal = @FundraisingGoal, Profile = @Profile
WHERE ParticipantID = @ParticipantID
Old May 23rd, 2004, 11:05 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik

Dear friend:
First of all let me say no1 is perfect & u can not be stumped since r working with Computer & coding for ASP .NET
But Secondly u r in wronge forum to ask ur ASPX question. Anyway...

I dont code with VB but I'll be happy to help.
Suppose ur code r fine, does ur SP works fine in Query Analyzer?
Where do u get error?!

Keep in touch.

Hovik Melkomian.

Similar Threads
Thread Thread Starter Forum Replies Last Post
no idea ! help lscjtw XSLT 4 July 23rd, 2007 09:55 AM
Brilliant idea, no idea how! imaginitive-idea-guy Ajax 9 January 14th, 2007 05:32 AM
Idea about project. shivanshub C# 0 August 20th, 2006 06:54 AM
Idea about project. shivanshub C# 0 August 15th, 2006 03:07 PM
DataSet idea melvik ADO.NET 3 May 5th, 2004 12:06 AM

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