datatype error

A

al

Hi , I am trying to update a table in the database:
I am getting error and I assume cause of the error is
because datatype for the ownership table does not match
the parameter so I am not sure how to fix it. any help
thanks
Al

table structure is as follow:
partnership_investor_id int
partnership_id int
investor_id int
ownership numeric(18,9)


The code to update is as follow:

as you can see when I declared parameter, I had to put
sqlDbType to varchar for ownership field. I
Sub dg_UpdateRow(sender As Object, e As
DataGridCommandEventArgs)
'Get information from columns...
Dim ddlPartnershipS as DropDownList = e.Item.Cells
(3).FindControl("ddlPartnership")
Dim ddlInvestorS as DropDownList = e.Item.Cells
(4).FindControl("ddlInvestor")
Dim OwnershipTextBox as TextBox = e.Item.Cells
(5).Controls(0)
Dim tblPK as String = dg.DataKeys(e.Item.ItemIndex)

'Update the database...
Dim strSQL as String
strSQL = "UPDATE partnership_investor " & _
" SET partnership_id = @Partnership_IdPara, Investor_id =
@Investor_IdPara, " & _
"Ownership = @OwnershipPara " & _
"WHERE partnership_investor_id =
@partnership_investor_idPara"

SQLStatement.Text= strSQL

Dim objCmd as New SqlCommand(SQLStatement.Text, objConn)
'declare parameterDim partnership_investor_idPara as New
SqlParameter("@partnership_investor_idPara",
SqlDbType.Char, 4)

Dim Partnership_IdPara as New SqlParameter
("@Partnership_IdPara", SqlDbType.Char, 4)
Dim Investor_IdPara as New SqlParameter
("@Investor_IdPara", SqlDbType.Char, 4)
Dim OwnershipPara as New SqlParameter
("@OwnershipPara", SqlDbType.VarChar, 15)

'populate para
partnership_investor_idPara.Value = tblPK
objCmd.Parameters.Add(partnership_investor_idPara)

Partnership_IdPara.Value =
ddlPartnershipS.SelectedItem.Value
objCmd.Parameters.Add(Partnership_IdPara)

Investor_IdPara.Value = ddlInvestorS.SelectedItem.Value
objCmd.Parameters.Add(Investor_IdPara)

OwnershipPara.Value = OwnershipTextBox.Text
objCmd.Parameters.Add(OwnershipPara)


'Issue the SQL command
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()

dg.EditItemIndex = -1
BindData()
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top