472,950 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 software developers and data experts.

Getting null value in datakeynames while Inserting ..

Iam get null values in the datakeynames AlertID,ItemID while executing the Insert Command....I am Inserting using Externel button Event.Here is the code of Gridiew ,Its datasource and the button event......Need help....

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView2" DataSourceID="SqlDataSource2" DataKeyNames="AlertID,ItemID" AutoGenerateColumns="False" runat="server"  Width="839px" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True">
  2.                     <Columns>
  3.                     <asp:BoundField DataField="AlertID" HeaderText="AlertID" SortExpression="AlertID" >
  4.                         <ItemStyle Width="10px" />
  5.                         <HeaderStyle Width="10px" />
  6.                     </asp:BoundField>
  7.                     <asp:BoundField DataField="OPCServer" HeaderText="Server" SortExpression="OPCServer" >
  8.                         <ItemStyle Width="40px" />
  9.                     </asp:BoundField>
  10.                     <asp:BoundField DataField="OPCItem" HeaderText="Item" SortExpression="OPCItem" />
  11.                     <asp:BoundField DataField="AlertType" HeaderText="AlertType" SortExpression="AlertType" />
  12.                     <asp:BoundField DataField="AlertValue" HeaderText="AlertValue" SortExpression="AlertValue" />
  13.  
  14.                      <asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" />
  15.                       <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
  16.                       <asp:BoundField DataField="AlertGroupAssignmentID" HeaderText="AlertGroupAssignmentID" SortExpression="AlertGroupAssignmentID" Visible="False" />
  17.                     <asp:TemplateField>
  18.                     <ItemTemplate>
  19.                     <asp:CheckBox runat="server" ID="chkbox"/>
  20.                     </ItemTemplate>
  21.                     </asp:TemplateField>
  22.  
  23.                     </Columns>
  24.            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  25.            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  26.            <EditRowStyle BackColor="#999999" />
  27.            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
  28.            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  29.            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  30.            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  31.  
  32.  
  33.                     </asp:GridView>
  34.  
  35.  
  36.  <asp:SqlDataSource
  37.         id="SqlDataSource2"
  38.         SelectCommand="Allalertgroupdata" InsertCommand="insert into AlertGroupAssignment (OPCItemID,OPCAlertID,AlertGroupID) values (@OPCItemID,@OPCAlertID,@AlertGroupID)"
  39.  
  40.         ConnectionString="<%$ ConnectionStrings:pumaalert %>"
  41.         Runat="server" SelectCommandType="StoredProcedure">
  42.         <SelectParameters>
  43.        <asp:SessionParameter SessionField="alertgpid" Name="alertgroup" />
  44.         <asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="filtergrp"  />
  45.         <asp:ControlParameter ControlID="TextBox1" PropertyName="Text" Name="criteria" />
  46.         </SelectParameters>
  47.        <InsertParameters>
  48.  
  49.        <asp:ControlParameter Name="OPCAlertID" ControlID="GridView2" PropertyName='SelectedDataKey("AlertID")' Type="Int32"  />
  50.        <asp:ControlParameter Name="OPCItemID" ControlID="GridView2" PropertyName='SelectedDataKey("ItemID")' Type="Int32" />
  51.         <asp:SessionParameter Name="AlertGroupID" Type="Int32"  SessionField="alertgpid" />
  52.        </InsertParameters>
  53.         </asp:SqlDataSource>
  54.  
  55.          <asp:SqlDataSource
  56.         id="addalertgroup"
  57.         SelectCommand="Dropdownalertgroup"
  58.         ConnectionString="<%$ ConnectionStrings:pumaalert %>"
  59.         Runat="server" SelectCommandType="StoredProcedure">
  60.          <SelectParameters>
  61.        <asp:SessionParameter Name="alertname" Type="String" SessionField="alertgpname" />
  62.  
  63.  
  64.         </SelectParameters>
  65.        </asp:SqlDataSource>
  66.  
  67.  
  68.  Protected Sub ImageButton8_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton8.Click
  69.         For Each row As GridViewRow In GridView2.Rows
  70.  
  71.             Dim checkbox As CheckBox = CType(row.FindControl("chkbox"), CheckBox)
  72.             If checkbox.Checked Then
  73.                 SqlDataSource2.Insert()
  74.  
  75.  
  76.  
  77.             End If
  78.  
  79.  
  80.         Next
  81.  
  82.     End Sub
Jul 14 '08 #1
0 1020

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marcus | last post by:
Hello, quick question about MySQL storing NULL values... Say I have a textbox called $_POST and a variable $var. if(empty($_POST)) $var = NULL; else $var = $_POST; Disregarding...
1
by: Jeff | last post by:
Hello all, I have an SQL Insert statement I'm trying to run via ExecuteNonQuery. It works fine so long as there are no nulls values. Here is the statement...(its a shortened version of what i...
7
by: Agnes | last post by:
In my table, the datafield set to be 'allownull', However, I want to set it as blank but not null. Should I put a space in the default value in sql database ? or, During inserting record, I...
1
by: rlueneberg | last post by:
I am having problem updating the value of a texbox control inside a gridview in which its bound field is also specified in DataKeyNames. What I noticed is that If I remove accountid from...
2
by: needin4mation | last post by:
Hi, I have a employee and address table. the address table has an addressid and and employeeid. I have two datagrids, an employee and address. The employee datagrid has a select. Clicking the...
0
by: gp | last post by:
I am and have been using PDO for about a year now...and have finally gotten around to solving the "DB NULL value" issues I ran into early on... I am looking for suggestions and techniques to...
10
by: Rahul Babbar | last post by:
Hi, I am getting the following error, while executing the simple insert script on a few tables. INSERT INTO <table_name>(<col1>) VALUES (1); DB2 SQL error: SQLCODE: -440, SQLSTATE: 42884,...
9
by: KDawg44 | last post by:
Hi, I have PHP function that adds a record to the database. The table has an ID that is AUTO_INCREMENT. Is there anyway to get that ID back when I do any kind of insert? That ID is a foreign...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...

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.