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