question about UpdateParameters.Add

  • Thread starter Thread starter Justin
  • Start date Start date
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
 
* 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
 
Thanks for the reply, but whe doing what you wrote, i get this very strange
error:
String was not recognized as a valid DateTime

...
 
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"?
 
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
 
"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.
 
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.
 
Back
Top