473,772 Members | 2,388 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid ParameterName not contained by SqlParameterCol lection

Hi. I'm just getting started with vb.NET development in VS 2003. I have a
datagrid that lists a bunch of customers (hospitals). Next to the customer
number and name is a bunch of checkboxes that I want to use to check whether
it's a key account, defensive account, ambulatory surgery center, academic
hospital, or MD office. The grid opens with the checkboxes in edit mode and
shows whether a box is checked or not. This initial binding is working fine.
The problem is when I try to use the edits to update the SQL database (for
all rows at once). I don't think my unique row identifier (AccountID) is
working. I'm getting the error "An SqlParameter with ParameterName
'@AccountID' is not contained by this SqlParameterCol lection...Line 52:
myCommand.Param eters("@Account ID").Value = AccountID"

Here's some of my HTML:
<asp:BoundColum n DataField="Acco untID" SortExpression= "AccountID"
HeaderText="ACC OUNT #"></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="KEY ">
<ItemTemplate >
<asp:CheckBox ID="cbKey" Enabled="True" Checked='<%#
Databinder.Eval (Container.Data Item, "KeyAccount ") %>' Runat="server" />
</ItemTemplate>
</asp:TemplateCol umn>
....etc. for the other checkboxes.

Here's my code behind:
Imports System.Data
Imports System.Data.Sql Client
Imports System.Text

Public Class AccountAttribut es
Inherits System.Web.UI.P age
Protected myComponent As New Component1
Protected WithEvents DemoGrid As System.Web.UI.W ebControls.Data Grid
Protected WithEvents btnUpdate As System.Web.UI.W ebControls.Butt on
Dim strConnNewProd As String =
ConfigurationSe ttings.AppSetti ngs("strConnNew Prod")

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
'Create a SqlConnection object.
'Modify the connection string as necessary for your environment.
Dim cn As SqlConnection = New
SqlConnection(" Server=NATWWW04 DEV\INET_DEV;UI D=EndoscopySqlU ser;PWD=2er@9b7 6m;Database=End oNewProduct")
Dim cmd As SqlCommand = New SqlCommand("Sel ect AccountID,
CUSTOMER_N, CITY, STATE_OR_R, KeyAccount, DefensiveAccoun t, [ASC], Academic,
Office FROM AccountAttribut es INNER JOIN dbo.tblAccountL ist ON
tblAccountList. CUSTOMER__ = AccountAttribut es.AccountID WHERE SALES_TERR =
90011326 ORDER BY CUSTOMER_N ASC", cn)
'Dim cmd As SqlCommand = New SqlCommand("Sel ect AccountID,
CUSTOMER_N, CITY, STATE_OR_R, SALES_TERR, KeyAccount, DefensiveAccoun t,
Academic, [ASC], Office FROM AccountAttribut es INNER JOIN dbo.tblAccountL ist
ON tblAccountList. CUSTOMER__ = AccountAttribut es.AccountID WHERE SALES_TERR =
" & _ID, cn)
cn.Open()
Dim reader As SqlDataReader = cmd.ExecuteRead er()
DemoGrid.DataSo urce = reader
DataBind()
reader.Close()
cn.Close()
End If
End Sub

'Use this to update all records at once
Private Sub btnUpdate_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles btnUpdate.Click

'Declarations
Dim cn As SqlConnection = New
SqlConnection(" Server=xxx;UID= xxx;PWD=xxx;Dat abase=xxx")
Dim strSQL As String = "Select AccountID, CUSTOMER_N, CITY,
STATE_OR_R, KeyAccount, DefensiveAccoun t, [ASC], Academic, Office FROM
AccountAttribut es INNER JOIN dbo.tblAccountL ist ON tblAccountList. CUSTOMER__
= AccountAttribut es.AccountID WHERE SALES_TERR = 90011326"
Dim myCommand As New SqlCommand(strS QL, cn)
Dim i As Integer
Dim dgi As DataGridItem
Dim AccountID As Integer
Dim cbKey, cbDef, cbASC, cbAca, cbMD As CheckBox

'Loop through the grid
For i = 0 To DemoGrid.Items. Count - 1
'Read in the values from the TemplateColumns
dgi = DemoGrid.Items( i)
AccountID = CType(AccountID , Integer)
cbKey = CType(dgi.FindC ontrol("cbKey") , CheckBox)
cbDef = CType(dgi.FindC ontrol("cbDef") , CheckBox)
cbASC = CType(dgi.FindC ontrol("cbASC") , CheckBox)
cbAca = CType(dgi.FindC ontrol("cbAca") , CheckBox)
cbMD = CType(dgi.FindC ontrol("cbMD"), CheckBox)

'Issue an UPDATE statement to the database
myCommand.Param eters("@Account ID").Value = AccountID
myCommand.Param eters("@KeyAcco unt").Value = cbKey.Checked
myCommand.Param eters("@Defensi veAccount").Val ue = cbDef.Checked
myCommand.Param eters("@ASC").V alue = cbASC.Checked
myCommand.Param eters("@Academi c").Value = cbAca.Checked
myCommand.Param eters("@Office" ).Value = cbMD.Checked

Dim updateSQL As String = "UPDATE AccountAttribut es SET
KeyAccount = @KeyAccount, DefensiveAccoun t = @DefensiveAccou nt WHERE
AccountID = @AccountID"

'Open the connection, update the data, close the connection
cn.Open()
myCommand.Execu teNonQuery()
cn.Close()
Next
End Sub
I'M REALLY FIRED UP ABOUT LEARNING HOW TO DO THIS AND I'VE SPENT AT LEAST 3
DAYS TRYING TO FIGURE OUT HOW TO DO IT TO NO AVAIL :( THANKS FOR ANY HELP!!

Nov 7 '05 #1
0 2085

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
301
by: Stephan | last post by:
Hi, I'm experiencing the problem mentioned in the title above. Briefly, I build a page in which I include a class. This class contains a procedure to add a value to an ArrayList. The value is hold by a structure. So all elements in the arraylist are in fact a structure. As you can see in the code below. Now what I'm trying to do is for each value in the Arraylist create and add a parameter. Then I try to execute a SP. This only works if...
4
1672
by: René Kabis | last post by:
People, I am at my wit's end. I am using the exact code from http://aspnet.4guysfromrolla.com/articles/071002-1.aspx And yet, the code does not manage to update the database. When I go to update my database, I am able to get the form fields, and I am able to replace the data, but when I go "update", the old data remains. I have done everything correct, including this:
0
252
by: Mike C | last post by:
Hi. I'm just getting started with vb.NET development in VS 2003. I have a datagrid that lists a bunch of customers (hospitals). Next to the customer number and name is a bunch of checkboxes that I want to use to check whether it's a key account, defensive account, ambulatory surgery center, academic hospital, or MD office. The grid opens with the checkboxes in edit mode and shows whether a box is checked or not. This initial binding is...
3
2158
by: Jason Huang | last post by:
Hi, In my C# Windows form project. I am wondering can we manually define the width of a cell in a DataGrid? Thanks for help. Jason
2
2962
by: DC | last post by:
The Code <%@ import namespace="System" %> <%@ import namespace="System.Web" %> <%@ import namespace="System.Web.UI" %> <%@ import namespace="System.Web.UI.HtmlControls" %> <%@ import namespace="System.Web.UI.WebControls" %> <%@ import namespace="System.Data" %> <%@ import namespace="System.Data.OleDb" %>
0
3584
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this OleDbParameterCollection" whenI try to write a new record. Delete and Modify work fine its just the add record function causes the error.
1
6479
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field (FieldName-Authorised) which has a datatype bit through DataGrid but not sure how to go about it. Any Ideas Guys on this one, your help is greatly appreciated. This is the procedure used to populate the datagrid, The primary key for the table is EntryID which...
2
5867
by: Brad Pears | last post by:
I have the following code that adds SQLParameter objects to an SQLParameterCollection object (well at least that's what I am trying to do!!) When the line of code runs that adds the parameter (colParams.Add), the actual function call (CreateSQLParam) executes with no errors but the actual ".add" fails with an "Object reference not set to an instance of an object" error. At first I thought it was maybe because I did not use the "New"...
1
5012
by: Dhananjay | last post by:
Hi all I have got this error An SqlParameter with ParameterName '@employment' is not contained by this SqlParameterCollection in asp.net
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7461
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.