Specified cast is not valid error

N

.Net Sports

I have a datagrid script where I modify data in an sql dbase in
asp.net, when i hit the "update" button, I get a Specified cast is not
valid error on my 'descript' declaration, whereas 'descript' is a
multiline text box and a varchar datatype (everything else is either a
char or a datetime datatype). Am I assigning 'descript' a wrong
datatype? Tried making it a nvarchar, still get same result

'''''''''''''''''''''''''''''''

Sub MyDataGrid_UpdateCommand(s As Object, e As DataGridCommandEventArgs
)
Dim conn As SQLConnection
Dim MyCommand As SQLCommand
Dim strConn as string = "Server=sql.mydomain.com;Initial
Catalog=mydb;User ID=DBxxx;Password=xxxxx;"
Dim company As textbox = E.Item.cells(2).Controls(0)
Dim address As textbox = E.Item.cells(3).Controls(0)
Dim city As textbox = E.Item.Cells(4).Controls(0)
Dim state As textbox = E.Item.cells(5).Controls(0)
Dim county As textbox = E.Item.cells(6).Controls(0)
Dim zip As textbox = E.Item.cells(7).Controls(0)
Dim phone As textbox = E.Item.cells(8).Controls(0)
'''''' the following line declaring the descript var is the line of the
error
Dim descript As textbox = E.Item.cells(9).Controls(0)
Dim web As textbox = E.Item.cells(10).Controls(0)
Dim email As textbox = E.Item.cells(11).Controls(0)
Dim datesold As textbox = E.Item.cells(12).Controls(0)
Dim dateexpire As textbox = E.Item.cells(13).Controls(0)

Dim strUpdateStmt As String
strUpdateStmt =" UPDATE CPAs SET" & _
" company = @company, address = @address, city = @city, state =
@state, " & _
"county = @county, zip = @zip, phone = @phone, descript =@
descript, " & _
"web = @web, email = @email, datesold = @datesold, dateexpire =
@dateexpire" & _
" WHERE cpaID = @cpaID"
conn = New SqlConnection(strConn)
MyCommand = New SqlCommand(strUpdateStmt, conn)
MyCommand.Parameters.Add(New SqlParameter("@company", company.text))
MyCommand.Parameters.Add(New SqlParameter("@address", address.text))
MyCommand.Parameters.Add(New SqlParameter("@city", city.text))
MyCommand.Parameters.Add(New SqlParameter("@state", state.text))
MyCommand.Parameters.Add(New SqlParameter("@county", county.text))
MyCommand.Parameters.Add(New SqlParameter("@zip", zip.text))
MyCommand.Parameters.Add(New SqlParameter("@phone", phone.text))
MyCommand.Parameters.Add(New SqlParameter("@descript", descript.text))
MyCommand.Parameters.Add(New SqlParameter("@web", web.text))
MyCommand.Parameters.Add(New SqlParameter("@email", email.text))
MyCommand.Parameters.Add(New SqlParameter("@datesold", datesold.text))
'', dateexpire =@dateexpire
MyCommand.Parameters.Add(New SqlParameter("@dateexpire",
dateexpire.text))

MyCommand.Parameters.Add(New SqlParameter("@cpaID",
e.Item.Cells(1).Text ))
conn.Open()
MyCommand.ExecuteNonQuery()
MyDataGrid.EditItemIndex = -1
conn.close
BindData
End Sub

'''''''''''''''''''''''''''''

netsports
 
C

Cowboy \(Gregory A. Beamer\)

How long is the text in the box? Is it constrained? If not you might have to
cast to a text type and give it a length which is long enough to hold the
amount of data that can be shoved into field. I also think there may be some
magic for a multi line text box, instead of placing the contents directly
into a parameter, try casting out as a string first and see if you get the
same issue.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top