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 1 1638
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.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA http://gregorybeamer.spaces.live.com
*************************************************
Think outside of the box!
*************************************************
".Net Sports" <ba********@cox.netwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
>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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tao |
last post by:
I just upgraded .NET framework to 1.1 and VS.Net to 2003 version and
tried to test it out. I created an ASP.NET project using the wizard
and tried to run
it by hitting "F5". I got an exception:...
|
by: Tyro |
last post by:
Can someone shed some light on my error here? Thanks!
Specified cast is not valid.
Exception Details: System.InvalidCastException: Specified cast is not
valid.
Source Error:
Stack Trace:
|
by: PK9 |
last post by:
I am looking for assistance in pinpointing the cause of the following
exception. I am getting a "Specified Cast is not valid" exception on my
page. I am trying to populate a datagrid. One of my...
|
by: Fabian |
last post by:
Hi,
I work with asp.net 2.0 and I have a intermittent error, only happens a few
times a day.
In the page I evaluate a Query String and then I get data form a database.
The code snipped:
...
|
by: VB Programmer |
last post by:
I am setting up forms authentication.
In my code I keep getting this error. Any ideas?
Error....
Server Error in '/LandOLots' Application....
| |
by: QA |
last post by:
I am using a Business Scorecard Accelarator in a Sharepoint Portal 2003
using SQL Server 2005
I am getting the following error:
Error,5/7/2005 10:50:14 AM,580,AUE1\Administrator,"Specified cast is...
|
by: Alan Z. Scharf |
last post by:
this question in datagrid group for several days with no
repsonse.
I'm hoping for an answer her because of greater activity in this group.
No cross-posting intended. Thanks....
|
by: Kashiefah |
last post by:
Hi, I keep on receiving this error when I click on the edit email link from the datagrid:Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the...
|
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= |
last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm
receiving a "Specified cast is not valid" error that has something to do w/
the keys involved. The stack trace is:
...
|
by: vinrin |
last post by:
Thank for your answer. :-)
call CheckEmptyNode (treeview)
public void CheckEmptyNode( Object N )
{
Microsoft.Web.UI.WebControls.TreeNode menuNode = null; ...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |