Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 21st, 2005, 05:25 PM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default help in updating record using visual studio code b


Hi experts. I made a form in visual studio.net that has 5 text boxes and a button. The form loads a perticuler record from matches table in to edit mode(primary key passed to this pageWebForm1.aspx?mach=34).
Then i allow the user to update the loaded record and press the button to update the loaded record.

Unfortunely when i edit one of the feilds and press the button, it loads the old data back without any change !! I be happy if some one help me fix this update problem.Thanks

Code:
Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
        Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlUpdateCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlDeleteCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
        Me.DataSet11 = New updatemachrecord.DataSet1
        CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.CommandText = "SELECT MATCHNO, TEAMNO, PLAYERNO, WON, LOST FROM MATCHES WHERE MATCHNO = @MATCHNO"
        Me.SqlSelectCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@MATCHNO", System.Data.SqlDbType.SmallInt, 2, "MATCHNO"))
        Me.SqlSelectCommand1.Connection = Me.SqlConnection1



        '
        'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = "Data Source=(local);Initial Catalog=teniss2;User ID=web;Password=web"
        '
        'SqlInsertCommand1
        '
        .....
        .....
        '
        'SqlUpdateCommand1
        '
        Me.SqlUpdateCommand1.CommandText = "UPDATE MATCHES SET MATCHNO = @MATCHNO, TEAMNO = @TEAMNO, PLAYERNO = @PLAYERNO, WO" & _
        "N = @WON, LOST = @LOST WHERE (MATCHNO = @Original_MATCHNO) AND (LOST = @Original" & _
        "_LOST OR @Original_LOST IS NULL AND LOST IS NULL) AND (PLAYERNO = @Original_PLAY" & _
        "ERNO) AND (TEAMNO = @Original_TEAMNO) AND (WON = @Original_WON OR @Original_WON " & _
        "IS NULL AND WON IS NULL); SELECT MATCHNO, TEAMNO, PLAYERNO, WON, LOST FROM MATCH" & _
        "ES WHERE (MATCHNO = @MATCHNO)"
        Me.SqlUpdateCommand1.Connection = Me.SqlConnection1
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@MATCHNO", System.Data.SqlDbType.SmallInt, 2, "MATCHNO"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@TEAMNO", System.Data.SqlDbType.SmallInt, 2, "TEAMNO"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@PLAYERNO", System.Data.SqlDbType.SmallInt, 2, "PLAYERNO"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@WON", System.Data.SqlDbType.SmallInt, 2, "WON"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LOST", System.Data.SqlDbType.SmallInt, 2, "LOST"))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_MATCHNO", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "MATCHNO", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_LOST", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "LOST", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_PLAYERNO", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "PLAYERNO", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_TEAMNO", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "TEAMNO", System.Data.DataRowVersion.Original, Nothing))
        Me.SqlUpdateCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Original_WON", System.Data.SqlDbType.SmallInt, 2, System.Data.ParameterDirection.Input, False, CType(0, Byte), CType(0, Byte), "WON", System.Data.DataRowVersion.Original, Nothing))
        '
        'SqlDeleteCommand1
        '
        ..........
        ..........

        '
        'SqlDataAdapter1
        '
        Me.SqlDataAdapter1.DeleteCommand = Me.SqlDeleteCommand1
        Me.SqlDataAdapter1.InsertCommand = Me.SqlInsertCommand1
        Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
        Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "MATCHES", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("MATCHNO", "MATCHNO"), New System.Data.Common.DataColumnMapping("TEAMNO", "TEAMNO"), New System.Data.Common.DataColumnMapping("PLAYERNO", "PLAYERNO"), New System.Data.Common.DataColumnMapping("WON", "WON"), New System.Data.Common.DataColumnMapping("LOST", "LOST")})})
        Me.SqlDataAdapter1.UpdateCommand = Me.SqlUpdateCommand1
        '
        'DataSet11
        '
        Me.DataSet11.DataSetName = "DataSet1"
        Me.DataSet11.Locale = New System.Globalization.CultureInfo("en-US")
        CType(Me.DataSet11, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub
    Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox3 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox4 As System.Web.UI.WebControls.TextBox
    Protected WithEvents TextBox5 As System.Web.UI.WebControls.TextBox
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents Label3 As System.Web.UI.WebControls.Label
    Protected WithEvents Label4 As System.Web.UI.WebControls.Label
    Protected WithEvents Label5 As System.Web.UI.WebControls.Label
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlInsertCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlUpdateCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlDeleteCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
    Protected WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
    Protected WithEvents DataSet11 As updatemachrecord.DataSet1

    '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.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not IsPostBack Then

            SqlSelectCommand1.Parameters(0).Value = Convert.ToInt16(Request.QueryString("match"))

            SqlDataAdapter1.Fill(DataSet11, "matches")

            TextBox1.DataBind()

            TextBox2.DataBind()

            TextBox3.DataBind()

            TextBox4.DataBind()

            TextBox5.DataBind()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SqlDataAdapter1.UpdateCommand.Parameters(0).Value = TextBox1.Text

        SqlDataAdapter1.UpdateCommand.Parameters(1).Value = TextBox2.Text

        SqlDataAdapter1.UpdateCommand.Parameters(2).Value = TextBox3.Text

        SqlDataAdapter1.UpdateCommand.Parameters(3).Value = TextBox4.Text

        SqlDataAdapter1.UpdateCommand.Parameters(4).Value = TextBox5.Text

        SqlDataAdapter1.UpdateCommand.Parameters(5).Value = 

        SqlDataAdapter1.UpdateCommand.Parameters(6).Value = 

        SqlDataAdapter1.UpdateCommand.Parameters(7).Value = 

        SqlDataAdapter1.UpdateCommand.Parameters(8).Value = 

        SqlDataAdapter1.UpdateCommand.Parameters(9).Value() =

        SqlDataAdapter1.Update(DataSet11)

        Response.Redirect("WebForm1.aspx?match=" & TextBox1.Text)
    End Sub
End Class

--------------------------------------------------------------------------------
Last edited by method : Today at 02:34 PM.
 
Old May 22nd, 2005, 07:01 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You have not provided your textboxes with any information as to how they should be bound.

I'd recommend you read about the SqlDataReader. You can load the values you are looking for with a simple query and an assignment from the DataReader to each textbox. This is a much easier and efficient way of doing this.

-Peter
 
Old May 22nd, 2005, 09:25 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank u for u reply. could u send me some tutorial about this SqlDataReader topics.thanks

 
Old May 23rd, 2005, 07:32 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Try googling SqlDataReader.

-Peter
 
Old May 23rd, 2005, 09:39 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well i managed to get it to point but it does not update my data when i click the button!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving Code behind in another folder Visual Studio ghari ASP.NET 1.0 and 1.1 Basics 1 December 23rd, 2005 10:21 AM
Using ASP.NET Code-Behind Without Visual Studio.NE rupen ASP.NET 1.0 and 1.1 Basics 0 October 12th, 2005 05:21 AM
Using Visual Studio vb.Net to build code sirandre007 Classic ASP Basics 1 March 28th, 2005 07:52 PM
Visual Studio solution file for sample code? davem1958 ASP.NET 1.0 and 1.1 Professional 1 October 10th, 2003 12:06 PM





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