An SqlParameter with ParameterName '@xxxx'is not contained by this SqlParameterCollection.

Hi all, on my quest to create an editable datagrid I am running into many problems!  For some reason the parameters in my update and delete commands are not happy they return the error above.  Why would it say that the parametername is not contained when its clearly there?  (I am referring to sqlcommand2 and sqlcommand3) please help!

many thankyou's!
Tom


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'connection
SqlConnection1.ConnectionString = ConfigurationSettings.AppSettings("ConnSkill")
Bindgrid()
End If
End Sub
Sub Bindgrid()
'assign username value
Dim bob As Integer = Request.QueryString.Get("person_id")
Dim dtrPerson As System.Data.SqlClient.SqlDataReader
'command
SqlCommand1.CommandText = "select * from person where person_id = '" & bob & "' "
SqlCommand1.CommandType = CommandType.Text
SqlCommand1.Connection = SqlConnection1
'init connection
SqlConnection1.Open()
DataGrid1.DataSource = SqlCommand1.ExecuteReader()
DataGrid1.DataBind()
SqlConnection1.Close()
'send to datagrid
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
Bindgrid()
End Sub
Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand
DataGrid1.EditItemIndex = -1
Bindgrid()
End Sub
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
'retreive textbox controls
Dim txtusername As TextBox
Dim txtfname As TextBox
Dim txtlname As TextBox
Dim txtpassword As TextBox
txtusername = CType(e.Item.Cells(1).Controls(0), TextBox)
txtfname = CType(e.Item.Cells(2).Controls(0), TextBox)
txtlname = CType(e.Item.Cells(3).Controls(0), TextBox)
txtpassword = CType(e.Item.Cells(4).Controls(0), TextBox)
SqlCommand2.Connection = SqlConnection1
SqlCommand2.CommandType = CommandType.Text
SqlCommand2.CommandText = "dUPDATE person SET username = @username, fname = @fname, lname = @lname, password = @password WHERE (person_ID = @person_ID)"
'assign parameters to sqlcommand
SqlCommand2.Parameters("@username").Value = txtusername.Text
SqlCommand2.Parameters("@fname").Value = txtfname.Text
SqlCommand2.Parameters("@lname").Value = txtlname.Text
SqlCommand2.Parameters("@password").Value = txtpassword.Text
SqlCommand2.Parameters("@person_id").Value = DataGrid1.DataKeys(e.Item.ItemIndex)
'execute command
SqlConnection1.Open()
SqlCommand2.ExecuteNonQuery()
SqlConnection1.Close()
'deselect row
DataGrid1.EditItemIndex = -1
Bindgrid()

End Sub
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand
SqlCommand3.Connection = SqlConnection1
SqlCommand3.CommandType = CommandType.Text
SqlCommand3.CommandText = "delete from person where (person_id = @person_id)"
SqlCommand3.Parameters("@person_id").Value = DataGrid1.DataKeys(e.Item.ItemIndex)
SqlConnection1.Open()
SqlCommand3.ExecuteNonQuery()
SqlConnection1.Close()
Bindgrid()

0
sexytom
2/13/2005 9:54:07 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1673 Views

Similar Articles

[PageSpeed] 5

In order to set the value of the parameter:

(SqlCommand2.Parameters("@username").Value = txtusername.Text)
you first need to define the parameter, i.e. create it and add to the Parameters collection of the command
Bug [MCSD]
0
bug_bugger
2/14/2005 9:40:51 AM
Thankyou, the book im learning from does not mention this but i have since added them and it works fine now :)

Tom
0
sexytom
2/14/2005 10:33:39 AM
Next question!  I have declared all of my parameters but get error still on: An SqlParameter with ParameterName '@level_ID' is not contained by this SqlParameterCollection. 


'submit to DB
SqlConnection1.Open()
SqlCommand1.Parameters("@Person_ID").Value = DDPerson.SelectedItem.Value
SqlCommand1.Parameters("@Route_ID").Value = DDRoute.SelectedItem.Value
SqlCommand1.Parameters("@Level_ID").Value = DDLevel.SelectedItem.Value
SqlCommand1.Parameters("@StartDate").Value = TBStart.Text
SqlCommand1.Parameters("@EndDate").Value = TBEnd.Text
SqlCommand1.Parameters("@Manager_ID").Value = DDManager.SelectedItem.Value
SqlCommand1.ExecuteNonQuery()
SqlConnection1.Close()
Response.Redirect("default.aspx")

These parameters have all been deifned, look:

Me.SqlCommand1.CommandText = "dbo.[addposition]"
Me.SqlCommand1.CommandType = System.Data.CommandType.StoredProcedure
Me.SqlCommand1.Connection = Me.SqlConnection1
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, False, CType(0, Byte), CType(0, Byte), "", System.Data.DataRowVersion.Current, Nothing))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Person_ID", System.Data.SqlDbType.Int, 4))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Route_ID", System.Data.SqlDbType.Int, 4))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@StartDate", System.Data.SqlDbType.DateTime, 8))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@EndDate", System.Data.SqlDbType.DateTime, 8))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@manager_ID", System.Data.SqlDbType.Int, 4))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@level_id", System.Data.SqlDbType.Int, 4))

If theyre defined why would i be getting this error?
thankyou muchly! .... Tom
0
sexytom
2/14/2005 12:28:05 PM
Reply:

Similar Artilces:

An SqlParameter with ParameterName '@productID' is not contained by this SqlParameterCollection.
Hello im implementing shopping cart for my site..However i get this error when i run the code {"An SqlParameter with ParameterName '@productID' is not contained by this SqlParameterCollection."} When i debugged, it stated that my line 90 has this error. This is my codebehind  1 Imports System.Data 2 Imports System.Data.SqlClient 3 4 Partial Class Checkout 5 Inherits System.Web.UI.Page 6 7 8 Protected Sub Wizard1_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) H...

An SqlParameter with ParameterName '@ID' is not contained by this SqlParameterCollection.
 Stored procedure:1 ALTER PROCEDURE [dbo].[insert_DagVerslag] 2 -- Add the parameters for the stored procedure here 3 @serverID int, 4 @datum datetime, 5 @ID int OUTPUT 6 AS 7 BEGIN 8 -- SET NOCOUNT ON added to prevent extra result sets from 9 -- interfering with SELECT statements. 10 SET NOCOUNT ON; 11 -- Insert statements for procedure here 12 BEGIN TRANSACTION 13 INSERT Log ( serverID, datum) 14 VALUES( @serverID, @datum) 15 COMMIT TRANSACTION 16 SET @ID = @@identity 17 END 18 &...

An SqlParameter with ParameterName '@AlumniID' is not contained by this SqlParameterCollection.
I receive the message in the subject line above with the following code. I would appreciate any assistance. Also, the close and dispose statements I have are probably a bit much. Any suggestions as to the most efficient way to handle the closure of the reader are welcome.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        Dim intAlumni As Integer        Dim strUser As String = Alumni.User        If Not IsPostBack Then&nb...

SqlParameter with ParameterName '@NewID' is not contained by this SqlParameterCollection
Hi,What I am trying to do is to get the new ID for every record is inserted into a table. I have a For...Each statement that does the loop and using the sqldatasource to so the insert.   <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ myConnectionString%>"> <InsertParameters> <asp:Parameter Name="NewID" Type="int16" Direction="output" /> </InsertParameters> </asp:SqlDataSource>  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Han...

The SqlParameter with ParameterName '@P__Detail__New1' is already contained by another SqlParameterCollection.
Using ADO.NET I open a database connection, I create a command and attach some parameters to it. I dispose of the command, close the connect and dispose of the connection. I open another connection and create a command which I attach parameters using the same parameter names as used in the first query. And I get the error as in the subject. Does anyone know why? And if there is anything that can be done about it? Code something like this.../* Code segment A */SqlConnection DbCon = new SqlConnection(/*With relevant parameters here*/);DbCon.Open();SqlCommand Command = new SqlCommand("...

An SqlParameter with ParameterName '@premium' is not contained by this SqlParameterCollection. ??? help plz
Can any one help plz getting this error An SqlParameter with ParameterName '@premium' is not contained by this SqlParameterCollection.when i try to get value of premium. Thank you in advance Function getpremium(ByVal ptypename As String, ByVal pcost As Integer) As Integer Dim premium1 As IntegerDim command As New SqlCommand("GetPremium") command.CommandType = CommandType.StoredProcedureWith command.Parameters .Add("@typename", Data.SqlDbType.NChar).Value = ptypename.Add("@cost", Data.SqlDbType.Int).Value = pcost End WithfuncDB.ExecNonQuery(comm...

System.IndexOutOfRangeException: An SqlParameter with ParameterName '@IPostSDescription' is not contained by this SqlParameterCollection
 my code: Database db = DatabaseFactory.CreateDatabase();            DbCommand cmd = db.GetStoredProcCommand("SP_SelectIdea");            db.AddInParameter(cmd, "IPostId", DbType.Int64, int.Parse(Request.QueryString["IPostId"]));            db.AddOutParameter(cmd, "IPostTitle", DbType.String, 150);            db.AddOutParamete...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

'System.Web.UI.Control' does not contain a definition for 'DataItem'
Hi, I am recieving this error: 'System.Web.UI.Control' does not contain a definition for 'DataItem' What iam trying to do is when a user clicks the hyperlink column in the datagrid then the ID of that user is send to another page and I need to run the Query or something and bind the Label on the page 2 with the name of the Person. So I am using the HTML view and writing something like this : '<%# DataBinder.Eval(Container.DataItem,"Name") %> ' here is my code behind file so how can i bind the Name of the person with the label: private void Page_Lo...

'System.Web.UI.Control' does not contain a definition for 'DataItem'
Hi, I am getting this error does anyone knows how to solve this :DHighOnCodingWanna get high! Show us the code that produces this error. Other than the exactness of the error, which explains what is exactly happening, we can't see why this is happening without seeing your code.David WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper - easily control properties for multiple controls with one control!Calendar Express - The Best HTML Calendar Generator on the web!(Please 'Mark as Answer' when i...

Getting 'System.Web.UI.Control' does not contain a definition for 'DataItem' error on controls when placed inside an update panel which is in a template.
Using the June CTP, I;ve got an updatepanel inside the itemtemplate of a datalist which is now suppopsed to be supported (it works). I also have some asp controls (imagebutton, label) which get their values dynamically (DataBinder.Eval(Container.DataItem, "fieldname").ToString(). This would work fine before putting the updatepanel in the datalist itemtemplate, I now get the error in the title when building ('System.Web.UI.Control' does not contain a definition for 'DataItem') for each control... How can I dynamically assign the values to the controls in the datalist when also using upd...

Repeater: nested controls cause error: 'object' does not contain a definition for 'DataItem'
I'm trying to use a Repeater control to create a series of other controls. The problem seems to be that when I try to access "Container.DataItem" the Container is now my nested control instead of the Repeater control. How do I get the Container.DataItem to point back to my Repeater instead of the nested control?   Sample code: <asp:Repeater ID="CardRepeater" runat="server"> <ItemTemplate>  <ComponentArt:Snap runat="server" ID="SnapCard" IsCollapsed="false"CurrentDockingIndex="0" Curre...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

Web resources about - An SqlParameter with ParameterName '@xxxx'is not contained by this SqlParameterCollection. - asp.net.presentation-controls

Resources last updated: 1/17/2016 12:14:40 AM