question about UpdateParameters.Add

Discussion in 'ASP .Net' started by Justin, Jul 30, 2007.

  1. Justin

    Justin Guest

    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, Jul 30, 2007
    #1
    1. Advertising

  2. * 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
    Jesse Houwing, Jul 30, 2007
    #2
    1. Advertising

  3. Justin

    Justin Guest

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

    ...


    "Jesse Houwing" <> schreef in bericht
    news:...
    >* 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
    Justin, Jul 30, 2007
    #3
  4. Justin

    Larry Bud Guest


    >
    > "Jesse Houwing" <> schreef in berichtnews:...
    >
    >
    >
    > >* 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"

    On Jul 30, 10:42 am, "Justin" <> wrote:

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


    It means the value you're passing in isn't a valid DateTime. What is
    vlgn equal to?
    Larry Bud, Jul 30, 2007
    #4
  5. Justin

    Justin Guest

    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"?


    "Larry Bud" <> schreef in bericht
    news:...
    >
    >>
    >> "Jesse Houwing" <> schreef in
    >> berichtnews:...
    >>
    >>
    >>
    >> >* 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"

    > On Jul 30, 10:42 am, "Justin" <> wrote:
    >
    >> Thanks for the reply, but whe doing what you wrote, i get this very
    >> strange
    >> error:
    >> String was not recognized as a valid DateTime

    >
    > It means the value you're passing in isn't a valid DateTime. What is
    > vlgn equal to?
    >
    Justin, Jul 30, 2007
    #5
  6. Justin

    SAL Guest

    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


    "Justin" <> wrote in message
    news:...
    > 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"?
    >
    >
    > "Larry Bud" <> schreef in bericht
    > news:...
    >>
    >>>
    >>> "Jesse Houwing" <> schreef in
    >>> berichtnews:...
    >>>
    >>>
    >>>
    >>> >* 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"

    >> On Jul 30, 10:42 am, "Justin" <> wrote:
    >>
    >>> Thanks for the reply, but whe doing what you wrote, i get this very
    >>> strange
    >>> error:
    >>> String was not recognized as a valid DateTime

    >>
    >> It means the value you're passing in isn't a valid DateTime. What is
    >> vlgn equal to?
    >>

    >
    >
    SAL, Jul 30, 2007
    #6
  7. Justin

    Larry Bud Guest

    On Jul 30, 11:59 am, "Justin" <> wrote:
    > "Larry Bud" <> schreef in berichtnews:...
    >
    >
    >
    >
    >
    > >> "Jesse Houwing" <> schreef in
    > >> berichtnews:...

    >
    > >> >* 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"

    > > On Jul 30, 10:42 am, "Justin" <> wrote:

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

    >
    > > It means the value you're passing in isn't a valid DateTime. What is
    > > vlgn equal to?-


    > 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.
    Larry Bud, Jul 30, 2007
    #7
  8. Justin

    Justin Guest

    Ok, thanks, i'll try ...

    "Larry Bud" <> schreef in bericht
    news:...
    > On Jul 30, 11:59 am, "Justin" <> wrote:
    >> "Larry Bud" <> schreef in
    >> berichtnews:...
    >>
    >>
    >>
    >>
    >>
    >> >> "Jesse Houwing" <> schreef in
    >> >> berichtnews:...

    >>
    >> >> >* 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"
    >> > On Jul 30, 10:42 am, "Justin" <> wrote:

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

    >>
    >> > It means the value you're passing in isn't a valid DateTime. What is
    >> > vlgn equal to?-

    >
    >> 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.
    >
    Justin, Jul 30, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?amtheW5l?=

    SqlDataSource UpdateParameters

    =?Utf-8?B?amtheW5l?=, Feb 28, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,947
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Mar 1, 2006
  2. =?Utf-8?B?YmlsbCB0aWU=?=

    UpdateParameters

    =?Utf-8?B?YmlsbCB0aWU=?=, Apr 4, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    4,999
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Apr 4, 2006
  3. Phillip Ian
    Replies:
    1
    Views:
    2,965
  4. Mike P

    GridView UpdateParameters

    Mike P, Apr 25, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    15,787
    =?Utf-8?B?Y2xpY2tvbg==?=
    Apr 25, 2006
  5. Replies:
    1
    Views:
    4,911
    elPako
    Aug 9, 2006
Loading...

Share This Page