sql update command
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-sqlclient' list.


Jeff Creasey
-- Moved from [aspdebug] to [ngfx-sqlclient] by Cain Marco <Click here to reveal e-mail address> --

Private Sub DataGrid_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid.UpdateCommand
Dim UpdateCmd As String = ("Update test Set testone=@test1,
testtwo=@test2 Where testone=@test0")
Dim MyCommand As SqlCommand = New SqlCommand(UpdateCmd,
MyConnection)
MyConnection = New
SqlConnection("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

MyCommand.Parameters.Add(New SqlParameter("@test1",
SqlDbType.VarChar, 10))
MyCommand.Parameters.Add(New SqlParameter("@test2",
SqlDbType.VarChar, 10))

MyCommand.Parameters("@test1").Value =
DataGrid.DataKeys(CInt(e.Item.ItemIndex))

Dim cols() As String = {"@test1", "@test2"}

MyCommand.Connection.Open()

MyCommand.ExecuteNonQuery()

MyCommand.Connection.Close()

BindGrid()
End Sub

Error when the update button is clicked
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.     

Stack Trace:

[ArgumentOutOfRangeException: Index was out of range. Must be non-negative
and less than the size of the collection. Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataKeyCollection.get_Item(Int32 index) +10
hardware.test.DataGrid_UpdateCommand(Object source, DataGridCommandEventArgs
e) +284
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs
e) +109 System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,
EventArgs e) +748 System.Web.UI.Control.RaiseBubbleEvent(Object source,
EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +100 System.Web.UI.Control.RaiseBubbleEvent(Object source,
EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +120
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Rai
sePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,
String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1263    

Reply to this message...
 
    
Tim Curtin
why do you have parenthesis around this statement?
Dim UpdateCmd As String = ("Update test Set testone=@test1,
testtwo=@test2 Where testone=@test0")

it should read:
Dim UpdateCmd As String = "Update test Set testone=@test1,
testtwo=@test2 Where testone=@test0"

[Original message clipped]

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Reply to this message...
 
    
Daniel Naumann
Jeff,

I don't see a parameter declaration for @test0, maybe that's your
problem.............

Daniel.

-----Original Message-----
From: Jeff Creasey [mailto:Click here to reveal e-mail address]
Sent: 13-Jun-2002 03:17
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] sql update command

-- Moved from [aspdebug] to [ngfx-sqlclient] by Cain Marco
<Click here to reveal e-mail address> --

Private Sub DataGrid_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid.UpdateCommand
Dim UpdateCmd As String = ("Update test Set testone=@test1,
testtwo=@test2 Where testone=@test0")
Dim MyCommand As SqlCommand = New SqlCommand(UpdateCmd,
MyConnection)
MyConnection = New
SqlConnection("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

MyCommand.Parameters.Add(New SqlParameter("@test1",
SqlDbType.VarChar, 10))
MyCommand.Parameters.Add(New SqlParameter("@test2",
SqlDbType.VarChar, 10))

MyCommand.Parameters("@test1").Value =
DataGrid.DataKeys(CInt(e.Item.ItemIndex))

Dim cols() As String = {"@test1", "@test2"}

MyCommand.Connection.Open()

MyCommand.ExecuteNonQuery()

MyCommand.Connection.Close()

BindGrid()
End Sub

Error when the update button is clicked
Index was out of range. Must be non-negative and less than the size of the
collection. Parameter name: index
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:

An unhandled exception was generated during the execution of the current web
request. Information regarding the origin and location of the exception can
be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Index was out of range. Must be non-negative
and less than the size of the collection. Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataKeyCollection.get_Item(Int32 index) +10
hardware.test.DataGrid_UpdateCommand(Object source, DataGridCommandEventArgs
e) +284
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs
e) +109 System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,
EventArgs e) +748 System.Web.UI.Control.RaiseBubbleEvent(Object source,
EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +100 System.Web.UI.Control.RaiseBubbleEvent(Object source,
EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +120
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.Rai
sePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,
String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1263

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
George Pagotelis
Are you using something like this?
http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quicksta
rt/aspplus/samples/webforms/data/datagrid6.src

Use a try/catch block (example below). It's been mentioned but your
missing declarations and values of those parameters. I see you have
cols() so I'm assuming you meant to cycle through the textboxes to get
the values. The above link shows you how to do it. Good Luck!

MyCommand.Connection.Open()
Try
    MyCommand.ExecuteNonQuery()
Message.InnerHtml = "<b>Record Updated</b><br>" &
UpdateCmd.ToString()
MyDataGrid.EditItemIndex = -1
Catch Exp As SQLException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: A record already exists with the same
primary key"
Else
Message.InnerHtml = "ERROR: Could not update record, please ensure
the fields are correctly filled out"
End If
Message.Style("color") = "red"
End Try

MyCommand.Connection.Close()

-----Original Message-----
From: Daniel Naumann [mailto:Click here to reveal e-mail address]
Sent: Thursday, 13 June 2002 7:55 AM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] RE: sql update command

Jeff,

I don't see a parameter declaration for @test0, maybe that's your
problem.............

Daniel.

-----Original Message-----
From: Jeff Creasey [mailto:Click here to reveal e-mail address]
Sent: 13-Jun-2002 03:17
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] sql update command

-- Moved from [aspdebug] to [ngfx-sqlclient] by Cain Marco
<Click here to reveal e-mail address> --

Private Sub DataGrid_UpdateCommand(ByVal source As Object, ByVal e
As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid.UpdateCommand
Dim UpdateCmd As String = ("Update test Set testone=@test1,
testtwo=@test2 Where testone=@test0")
Dim MyCommand As SqlCommand = New SqlCommand(UpdateCmd,
MyConnection)
MyConnection = New
SqlConnection("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

MyCommand.Parameters.Add(New SqlParameter("@test1",
SqlDbType.VarChar, 10))
MyCommand.Parameters.Add(New SqlParameter("@test2",
SqlDbType.VarChar, 10))

MyCommand.Parameters("@test1").Value =
DataGrid.DataKeys(CInt(e.Item.ItemIndex))

Dim cols() As String = {"@test1", "@test2"}

MyCommand.Connection.Open()

MyCommand.ExecuteNonQuery()

MyCommand.Connection.Close()

BindGrid()
End Sub

Error when the update button is clicked
Index was out of range. Must be non-negative and less than the size of
the
collection. Parameter name: index
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:

An unhandled exception was generated during the execution of the current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Index was out of range. Must be
non-negative
and less than the size of the collection. Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataKeyCollection.get_Item(Int32 index) +10
hardware.test.DataGrid_UpdateCommand(Object source,
DataGridCommandEventArgs
e) +284
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventA
rgs
e) +109 System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object
source,
EventArgs e) +748 System.Web.UI.Control.RaiseBubbleEvent(Object
source,
EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +100 System.Web.UI.Control.RaiseBubbleEvent(Object
source,
EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +120
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler
.Rai
sePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl,
String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1263

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
    
Arief Budimartoyo
Jeff, it's looks like your selected item, didn't have an index key on
datagrid items.
so error would happened because you didn't have any value while get
e.Item.ItemIndex variable.

-----Original Message-----
From: George Pagotelis [mailto:Click here to reveal e-mail address]
Sent: Thursday, June 13, 2002 8:07 AM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] RE: sql update command

Are you using something like this?
http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quicksta
rt/aspplus/samples/webforms/data/datagrid6.src

Use a try/catch block (example below). It's been mentioned but your
missing declarations and values of those parameters. I see you have
cols() so I'm assuming you meant to cycle through the textboxes to get
the values. The above link shows you how to do it. Good Luck!

MyCommand.Connection.Open()
Try
    MyCommand.ExecuteNonQuery()
Message.InnerHtml = "<b>Record Updated</b><br>" &
UpdateCmd.ToString()
MyDataGrid.EditItemIndex = -1
Catch Exp As SQLException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: A record already exists with the same
primary key"
Else
Message.InnerHtml = "ERROR: Could not update record, please ensure
the fields are correctly filled out"
End If
Message.Style("color") = "red"
End Try

MyCommand.Connection.Close()

-----Original Message-----
From: Daniel Naumann [mailto:Click here to reveal e-mail address]
Sent: Thursday, 13 June 2002 7:55 AM
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] RE: sql update command

Jeff,

I don't see a parameter declaration for @test0, maybe that's your
problem.............

Daniel.

-----Original Message-----
From: Jeff Creasey [mailto:Click here to reveal e-mail address]
Sent: 13-Jun-2002 03:17
To: ngfx-sqlclient
Subject: [ngfx-sqlclient] sql update command

-- Moved from [aspdebug] to [ngfx-sqlclient] by Cain Marco
<Click here to reveal e-mail address> --

Private Sub DataGrid_UpdateCommand(ByVal source As Object, ByVal e
As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid.UpdateCommand
Dim UpdateCmd As String = ("Update test Set testone=@test1,
testtwo=@test2 Where testone=@test0")
Dim MyCommand As SqlCommand = New SqlCommand(UpdateCmd,
MyConnection)
MyConnection = New
SqlConnection("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

MyCommand.Parameters.Add(New SqlParameter("@test1",
SqlDbType.VarChar, 10))
MyCommand.Parameters.Add(New SqlParameter("@test2",
SqlDbType.VarChar, 10))

MyCommand.Parameters("@test1").Value =
DataGrid.DataKeys(CInt(e.Item.ItemIndex))

Dim cols() As String = {"@test1", "@test2"}

MyCommand.Connection.Open()

MyCommand.ExecuteNonQuery()

MyCommand.Connection.Close()

BindGrid()
End Sub

Error when the update button is clicked
Index was out of range. Must be non-negative and less than the size of
the
collection. Parameter name: index
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of
range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:

An unhandled exception was generated during the execution of the current
web
request. Information regarding the origin and location of the exception
can
be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Index was out of range. Must be
non-negative
and less than the size of the collection. Parameter name: index]
System.Collections.ArrayList.get_Item(Int32 index) +91
System.Web.UI.WebControls.DataKeyCollection.get_Item(Int32 index) +10
hardware.test.DataGrid_UpdateCommand(Object source,
DataGridCommandEventArgs
e) +284
System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventA
rgs
e) +109 System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object
source,
EventArgs e) +748 System.Web.UI.Control.RaiseBubbleEvent(Object
source,
EventArgs args) +26
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e) +100 System.Web.UI.Control.RaiseBubbleEvent(Object
source,
EventArgs args) +26
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +120
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler
.Rai
sePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl,
String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
System.Web.UI.Page.ProcessRequestMain() +1263

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

| [ngfx-sqlclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/ngfx-sqlclient.asp = JOIN/QUIT

Reply to this message...
 
 
System.ArgumentOutOfRangeException
System.Collections.ArrayList
System.Collections.Specialized.NameValueCollection
System.Data.SqlClient.SqlCommand
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlParameter
System.Data.SqlDbType
System.EventArgs
System.Messaging.Message
System.Web.UI.Control
System.Web.UI.IPostBackEventHandler
System.Web.UI.Page
System.Web.UI.WebControls.CommandEventArgs
System.Web.UI.WebControls.DataGrid
System.Web.UI.WebControls.DataGridCommandEventArgs
System.Web.UI.WebControls.DataGridItem
System.Web.UI.WebControls.DataKeyCollection
System.Web.UI.WebControls.LinkButton
System.Windows.Forms.DataGrid




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com