p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   SQL Server 2005 (http://p2p.wrox.com/forumdisplay.php?f=220)
-   -   problem with Updating a table (http://p2p.wrox.com/showthread.php?t=60767)

hertendreef August 2nd, 2007 03:31 PM

problem with Updating a table
 
Hi,

i try to update field 'name' (nvarchar(5) in sql server) of table 'mytable'.
This happens in event DetailsView1_ItemUpdating with my own code.
It works without parameters (i know, bad way) like this:
SqlDataSource1.UpdateCommand = "UPDATE mytable set name= '" & na & "'"

But when using parameters like here below, i get the error:
"Input string was not in a correct format"

Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewUpdateEventAr gs) Handles
DetailsView1.ItemUpdating
SqlDataSource1.UpdateCommand = "UPDATE mytable set name= @myname"
SqlDataSource1.UpdateParameters.Add("@myname", SqlDbType.NVarChar, na)
SqlDataSource1.Update()
End Sub

I don't see what's wrong here.
Thanks for help
Mark




gaurav_jain2403 August 4th, 2007 02:47 AM

This line is incorrect:-
SqlDataSource1.UpdateParameters.Add("@myname", SqlDbType.NVarChar, na)

You should write it as follow:-
SqlDataSource1.UpdateParameters.Add("@myname", System.TypeCode.String, na)


All times are GMT -4. The time now is 11:44 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.