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>
|