Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional 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 October 14th, 2004, 03:39 PM
Authorized User
 
Join Date: May 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default INSERT Problem with a web form

The form uses data from an existing record and allows to create a new one with some of the existing data.

Obviously, no two records can be identical, so there's a constraint on the table that spans three columns (Logical_Name, Physical_Name, and Table_ID) preventing identical values in those three columns to be used on a new record.

This works just fine SQL-wise at a prompt, because I can do inserts directly on the DB server but the aspx page appears not to be reading the modified values in the text boxes, and instead keeps sending the original values, effectively throwing a constraint violation error every time.

This is the first time I'm doing this type of form in ASP.NET, so here's the code for the insert Sub:

<code>
Sub subBtnClick( s As Object, e As EventArgs )
        Dim strInsert, radReq As String
        Dim cmdInsert As SqlCommand
        If radYes.checked
            radReq = "Yes"
        Else
            radReq = "No"
        End If
        conMeta = New SqlConnection( "Server='DOHSDBS96';trusted_connection=true;Databa se='METADATAv2'" )
        strInsert = "INSERT INTO A_T_Field (Logical_Name,Physical_Name,[Description],Edit_Mask,atfSize,atfDecimal," & _
        "atfDomain,Business_Rule,Required,Default_Value,Ta ble_ID,Data_Type_ID,Quality_ID,Status_ID)" & _
        "VALUES (@lName,@pName,@desc,@eMask,@size,@dcml,@domn,@bRu le,@req,@dValue,@tblID,@dtID,@qualID,@statID)"

        'cmdInsert = New SqlCommand( "sTblAddNew", conMeta )
        'cmdInsert.CommandType = CommandType.StoredProcedure
        cmdInsert = New SqlCommand( strInsert, conMeta )
        cmdInsert.Parameters.Add( "@lName", txtLogiName.Text )
        cmdInsert.Parameters.Add( "@pName", txtPhysName.Text )
        cmdInsert.Parameters.Add( "@desc", txtDesc.Text )
        cmdInsert.Parameters.Add( "@eMask", txtEditMask.Text )
        cmdInsert.Parameters.Add( "@size", txtSize.Text )
        cmdInsert.Parameters.Add( "@dcml", txtDecimal.Text )
        cmdInsert.Parameters.Add( "@domn", txtDomain.Text )
        cmdInsert.Parameters.Add( "@bRule", txtBusRule.Text )
        cmdInsert.Parameters.Add( "@req", radReq )
        cmdInsert.Parameters.Add( "@dValue", txtDefValue.Text )
        cmdInsert.Parameters.Add( "@tblID", txtTblID.Text )
        cmdInsert.Parameters.Add( "@dtID", ddlDataType.SelectedItem.Value )
        cmdInsert.Parameters.Add( "@qualID", ddlQualities.SelectedItem.Value )
        cmdInsert.Parameters.Add( "@statID", ddlStatus.SelectedItem.Value )
        Try
            conMeta.Open()
            cmdInsert.ExecuteNonQuery()
            conMeta.Close()
            lblInsrtResults.Text = "Field " & txtLogiName.text & " has been CREATED!"
        Catch
            lblInsrtError.Text = "Sorry, a record already exists with the same Field ID, Logical Name, and Physical Name!"
        End Try
    End Sub
    Sub Page_Load(s As Object, e As EventArgs)
        If Not Page.IsPostBack Then
            lblTblID.Text = Context.Items("tblID")
            lblFldID.Text = Request.QueryString( "fldID" )
            txtLogiName.Text = Context.Items("fldLogiName")
        End If
        BindData()
        BindDDLs()
    End Sub
</code>

 
Old October 23rd, 2004, 09:06 AM
Authorized User
 
Join Date: Oct 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default


1 are you indexing any other field as unique?

2 are you using cache?

3 stop your program at 'try' line and display all fields that make yor key or use trace.warn at Page_Load and subBtnClick

wagner reatto





Similar Threads
Thread Thread Starter Forum Replies Last Post
Web Form Email Job Problem kwilliams ASP.NET 2.0 Professional 2 June 24th, 2008 02:27 PM
Problem loading report on a web form Imar BOOK: Professional Crystal Reports for VS.NET 1 January 15th, 2007 09:27 PM
dealing with concurrency using web form insert method SQL Server 2000 1 May 23rd, 2005 04:09 PM
Database Insert/Update problem with VB.NET form tino mclaren VB Databases Basics 2 February 4th, 2005 05:12 AM
web form control problem myavi ADO.NET 1 June 5th, 2004 12:16 AM





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