Wrong Value Going Into DB

Results 1 to 2 of 2

Thread: Wrong Value Going Into DB

  1. #1
    Join Date
    Dec 1969

    Default Wrong Value Going Into DB

    I have the following code, which whenever gets called, it places the value of ProposalID in the Amount column. <BR><BR>[code language="VB.NET"]<BR>Sub dgRevisions_Insert(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)<BR> If e.CommandName = "Insert" Then<BR> Dim revisedYear As Integer<BR> Dim revisedEquipment As String<BR> Dim revisedAmount As Integer<BR><BR> Response.Write("Proposal ID: " & trim(cstr(Session("revisionID"))) & "&#060;BR /&#062;")<BR><BR> revisedYear = Cint(CType(e.Item.FindControl("add_Year"), TextBox).Text.Trim())<BR> <BR> Response.Write("Year: " & cstr(revisedYear) & "&#060;BR /&#062;")<BR> <BR> revisedEquipment = CType(e.Item.FindControl("add_Equipment"), TextBox).Text.Trim()<BR> <BR> Response.Write("Equipment: " & revisedEquipment & "&#060;BR /&#062;")<BR> <BR> revisedAmount = Cint(CType(e.Item.FindControl("add_Amount"), TextBox).Text.Trim())<BR> <BR> Response.Write("Amount: " & cstr(revisedAmount) & "&#060;BR /&#062;")<BR> <BR> &#039;Create the appropriate SQL statement<BR> Dim strSQL As String = "INSERT INTO Proposal_ID_Year_Equipment " & _<BR> "VALUES (?,?,?)"<BR> <BR> Const strConnString As String = _<BR> "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:inetpubwwwrootGrantProposalDatabase.mdb"< BR> Dim objConn As New OleDbConnection(strConnString)<BR> objConn.Open()<BR> <BR> <BR> Dim parmProposalID As New OleDbParameter("@proposalID", OleDbType.VarChar, 100)<BR> parmProposalID.Direction = ParameterDirection.Input<BR> Dim parmYear As New OleDbParameter("@year", OleDbType.Integer)<BR> parmYear.Direction = ParameterDirection.Input<BR> Dim parmEquipment As New OleDbParameter("@equipment", OleDbType.VarChar, 100)<BR> parmEquipment.Direction = ParameterDirection.Input<BR> Dim parmProposalID2 As New OleDbParameter("@proposalID", OleDbType.VarChar, 100)<BR> parmProposalID2.Direction = ParameterDirection.Input<BR> Dim parmYear2 As New OleDbParameter("@year", OleDbType.Integer)<BR> parmYear2.Direction = ParameterDirection.Input<BR> Dim parmEquipment2 As New OleDbParameter("@equipment", OleDbType.VarChar, 100)<BR> parmEquipment2.Direction = ParameterDirection.Input<BR> Dim parmAmount As New OleDbParameter("@amount", OleDbType.Currency)<BR> parmAmount.Direction = ParameterDirection.Input<BR> <BR> Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, objConn)<BR> <BR> <BR> myCommand.CommandType = CommandType.Text<BR> <BR> parmProposalID.Value = trim(cstr(Session("revisionID")))<BR> parmYear.Value = revisedYear<BR> parmEquipment.Value = revisedEquipment<BR><BR> myCommand.Parameters.Add(parmProposalID)<BR> myCommand.Parameters.Add(parmYear)<BR> myCommand.Parameters.Add(parmEquipment)<BR> myCommand.ExecuteNonQuery() &#039;Execute the UPDATE query<BR><BR> <BR> strSQL = "INSERT INTO Proposal_ID_Year_Equipment_Amount " & _<BR> "VALUES (?,?,?,?)"<BR> <BR> myCommand.CommandText = strSQL<BR> <BR> myCommand.Parameters.Add(parmProposalID2)<BR> myCommand.Parameters.Add(parmYear2)<BR> myCommand.Parameters.Add(parmEquipment2)<BR> myCommand.Parameters.Add(parmAmount)<BR><BR> parmProposalID2.Value = trim(cstr(Session("revisionID")))<BR> parmYear2.Value = revisedYear <BR> parmAmount.Value = revisedAmount<BR><BR> parmEquipment2.Value = revisedEquipment<BR><BR> <BR> myCommand.ExecuteNonQuery() &#039;Execute the UPDATE query<BR><BR> objConn.Close()<BR><BR> <BR> &#039;Rebind the DataGrid<BR> dgRevisions.EditItemIndex = -1<BR> BindData()<BR> End If<BR>End Sub<BR><BR>[/code]<BR>The two tables looks like this: Proposal_ID_Year_Equipment = {PROPOSALID, YEAR, EQUIPMENT} and Proposal_ID_Year_Equipment_Amount = {PROPOSALID, YEAR, EQUIPMENT, AMOUNT}.

  2. #2
    Join Date
    Dec 1969

    Default RE: Wrong Value Going Into DB

    I&#039;d say step thru the code and make sure your passing the right value to the right paramter.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts