Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

question about UpdateParameters.Add

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Justin - 30 Jul 2007 15:11 GMT
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
Jesse Houwing - 30 Jul 2007 15:21 GMT
* Justin wrote, On 30-7-2007 16:11:
> Hi,
>
[quoted text clipped - 20 lines]
> 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 - 30 Jul 2007 15:42 GMT
Thanks for the reply, but whe doing what you wrote, i get this very strange
error:
String was not recognized as a valid DateTime

..

>* Justin wrote, On 30-7-2007 16:11:
>> Hi,
[quoted text clipped - 29 lines]
>
> Jesse
Larry Bud - 30 Jul 2007 16:04 GMT
> >* Justin wrote, On 30-7-2007 16:11:
> >> Hi,
[quoted text clipped - 27 lines]
> > SqlDataSource1.UpdateParameters.Add("@vlg", SqlDbType.SmallInt, vlgn)
> > SqlDataSource1.UpdateCommand = "UPDATE mytable set vlg=@vlg"

> 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 - 30 Jul 2007 16:59 GMT
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"?

>> >* Justin wrote, On 30-7-2007 16:11:
>> >> Hi,
[quoted text clipped - 36 lines]
> It means the value you're passing in isn't a valid DateTime.  What is
> vlgn equal to?
SAL - 30 Jul 2007 17:13 GMT
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

> 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"?
[quoted text clipped - 41 lines]
>> It means the value you're passing in isn't a valid DateTime.  What is
>> vlgn equal to?
Larry Bud - 30 Jul 2007 19:19 GMT
> >> >* Justin wrote, On 30-7-2007 16:11:
> >> >> Hi,
[quoted text clipped - 36 lines]
> > 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 - 30 Jul 2007 20:55 GMT
Ok, thanks, i'll try ...

>> >> >* Justin wrote, On 30-7-2007 16:11:
>> >> >> Hi,
[quoted text clipped - 51 lines]
> capture the SQL that's being generated from your app by using SQL
> Profiler.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.