question about UpdateParameters.Add

J

Justin

Hi,

this code updates a table with the new values with the event RowUpdating of
a gridview.

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating

Dim vlgn As Int16
vlgn = e.NewValues("vlg")

SqlDataSource1.UpdateCommand = "UPDATE mytable set vlg=" & vlgn

This works.
Now i want to use parameters (without creating a stored procedure). I tried
this but fails:

SqlDataSource1.UpdateParameters.Add("vlg", SqlDbType.SmallInt, vlgn)
SqlDataSource1.UpdateCommand = "UPDATE mytable set vlg=vlg"

Could somebody give me the right syntax for this?
Thanks
Justin
 
J

Jesse Houwing

* Justin wrote, On 30-7-2007 16:11:
Hi,

this code updates a table with the new values with the event RowUpdating of
a gridview.

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating

Dim vlgn As Int16
vlgn = e.NewValues("vlg")

SqlDataSource1.UpdateCommand = "UPDATE mytable set vlg=" & vlgn

This works.
Now i want to use parameters (without creating a stored procedure). I tried
this but fails:

SqlDataSource1.UpdateParameters.Add("vlg", SqlDbType.SmallInt, vlgn)
SqlDataSource1.UpdateCommand = "UPDATE mytable set vlg=vlg"

Could somebody give me the right syntax for this?
Thanks
Justin

The parameter has a specific, unique name and usually starts with a '@'
sign:

SqlDataSource1.UpdateParameters.Add("@vlg", SqlDbType.SmallInt, vlgn)
SqlDataSource1.UpdateCommand = "UPDATE mytable set vlg=@vlg"

Jesse
 
J

Justin

Thanks for the reply, but whe doing what you wrote, i get this very strange
error:
String was not recognized as a valid DateTime

...
 
J

Justin

The value is a smallint (50). It has nothing to do with datetime.
Has it something to do with the fact i use the event "RowUpdating"?
 
S

SAL

Hmmm, suspicious!
I'm going to guess that there's a date field in your grid and that the grid
is actually trying to update that field. I've had this happen on a few
occasions and what I had to do was to check the values that were in the row
and set the offending value to null, if that's what it should be...

Poke around a bit and you may find the same thing...

HTH
S
 
L

Larry Bud

"Larry Bud" <[email protected]> schreef in bericht
The value is a smallint (50). It has nothing to do with datetime.
Has it something to do with the fact i use the event "RowUpdating"?

Please post your reply at the bottom so the conversation follows a
logical flow...

Can you run your SQL statement Query Analyzer? If so, you need to
capture the SQL that's being generated from your app by using SQL
Profiler.
 
J

Justin

Ok, thanks, i'll try ...

Larry Bud said:
Please post your reply at the bottom so the conversation follows a
logical flow...

Can you run your SQL statement Query Analyzer? If so, you need to
capture the SQL that's being generated from your app by using SQL
Profiler.
 

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

Forum statistics

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

Latest Threads

Top