473,327 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 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 1041

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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.