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_Upda teCommand(s As Object, e As DataGridCommand EventArgs
)
Dim conn As SQLConnection
Dim MyCommand As SQLCommand
Dim strConn as string = "Server=sql.myd omain.com;Initi al
Catalog=mydb;Us er ID=DBxxx;Passwo rd=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(s trConn)
MyCommand = New SqlCommand(strU pdateStmt, conn)
MyCommand.Param eters.Add(New SqlParameter("@ company", company.text))
MyCommand.Param eters.Add(New SqlParameter("@ address", address.text))
MyCommand.Param eters.Add(New SqlParameter("@ city", city.text))
MyCommand.Param eters.Add(New SqlParameter("@ state", state.text))
MyCommand.Param eters.Add(New SqlParameter("@ county", county.text))
MyCommand.Param eters.Add(New SqlParameter("@ zip", zip.text))
MyCommand.Param eters.Add(New SqlParameter("@ phone", phone.text))
MyCommand.Param eters.Add(New SqlParameter("@ descript", descript.text))
MyCommand.Param eters.Add(New SqlParameter("@ web", web.text))
MyCommand.Param eters.Add(New SqlParameter("@ email", email.text))
MyCommand.Param eters.Add(New SqlParameter("@ datesold", datesold.text))
'', dateexpire =@dateexpire
MyCommand.Param eters.Add(New SqlParameter("@ dateexpire",
dateexpire.text ))
MyCommand.Param eters.Add(New SqlParameter("@ cpaID",
e.Item.Cells(1) .Text ))
conn.Open()
MyCommand.Execu teNonQuery()
MyDataGrid.Edit ItemIndex = -1
conn.close
BindData
End Sub
''''''''''''''' ''''''''''''''
netsports 1 1644
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******** *************@m 73g2000cwd.goog legroups.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_Upda teCommand(s As Object, e As DataGridCommand EventArgs
)
Dim conn As SQLConnection
Dim MyCommand As SQLCommand
Dim strConn as string = "Server=sql.myd omain.com;Initi al
Catalog=mydb;Us er ID=DBxxx;Passwo rd=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(s trConn)
MyCommand = New SqlCommand(strU pdateStmt, conn)
MyCommand.Param eters.Add(New SqlParameter("@ company", company.text))
MyCommand.Param eters.Add(New SqlParameter("@ address", address.text))
MyCommand.Param eters.Add(New SqlParameter("@ city", city.text))
MyCommand.Param eters.Add(New SqlParameter("@ state", state.text))
MyCommand.Param eters.Add(New SqlParameter("@ county", county.text))
MyCommand.Param eters.Add(New SqlParameter("@ zip", zip.text))
MyCommand.Param eters.Add(New SqlParameter("@ phone", phone.text))
MyCommand.Param eters.Add(New SqlParameter("@ descript", descript.text))
MyCommand.Param eters.Add(New SqlParameter("@ web", web.text))
MyCommand.Param eters.Add(New SqlParameter("@ email", email.text))
MyCommand.Param eters.Add(New SqlParameter("@ datesold", datesold.text))
'', dateexpire =@dateexpire
MyCommand.Param eters.Add(New SqlParameter("@ dateexpire",
dateexpire.text ))
MyCommand.Param eters.Add(New SqlParameter("@ cpaID",
e.Item.Cells(1) .Text ))
conn.Open()
MyCommand.Execu teNonQuery()
MyDataGrid.Edit ItemIndex = -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: "Specified cast is not valid."
The only thing i put there was a "test this." inside the form. What
might be the problem here?
Thanks in advance.
...
|
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 columns is a template
column where I'd like to evaluate the data brought back from the db and
populate the column with a "Y" or "N" depending on the...
|
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:
try
{
|
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
not
valid.","Microsoft.BusinessIntelligence.Scorecard.ScorecardException:
Specified cast is not valid. --->...
|
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.
-----------------------------------------------------------
Server
VS.NET 2003
SQLServer 2000
IIS 66.0
|
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 current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:...
|
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:
======================
Message: Specified cast is not valid.
Type: System.InvalidCastException
Source: System.Data.Linq
TargetSite: Boolean...
|
by: vinrin |
last post by:
Thank for your answer. :-)
call CheckEmptyNode (treeview)
public void CheckEmptyNode( Object N )
{
Microsoft.Web.UI.WebControls.TreeNode menuNode = null;
Microsoft.Web.UI.WebControls.TreeNode iNode = 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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |