﻿<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Intersoft Community - WebGrid Enterprise - How to get auto-increment column value back into webgrid after insert?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-get-auto-increment-column-value-back-into-webgrid-after-insert/</link><description /><generator>http://www.intersoftsolutions.com</generator><language>en</language><copyright>Copyright 2002 - 2015 Intersoft Solutions Corp. All rights reserved.</copyright><ttl>60</ttl><item><title>How to get auto-increment column value back into webgrid after insert?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-get-auto-increment-column-value-back-into-webgrid-after-insert/</link><pubDate>Tue, 16 Oct 2012 21:58:56 GMT</pubDate><dc:creator>bernard</dc:creator><description>Hi TJ,&lt;div&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;I think you must handle the select and insert method besides adding ref value on your parameter. I've search for the sample of KB. In that sample, you can find dsNorthwind.cs that describe you how to handle identity value. I attach the sample here. Please let me know if there's misconfiguration in that sample. Hope this helps.&lt;/div&gt;
&lt;div&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;Regards,&lt;br /&gt;Bernard&lt;/div&gt;</description></item><item><title>How to get auto-increment column value back into webgrid after insert?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-get-auto-increment-column-value-back-into-webgrid-after-insert/</link><pubDate>Tue, 16 Oct 2012 05:08:15 GMT</pubDate><dc:creator>throstur62</dc:creator><description>&lt;p&gt;Hi Bernard,&lt;br /&gt;I read your article. Unfortunately the attached code-sample is not accessible any more. However from that article I read that the only thing I had to do was to change the first parameter of my Insert method to be a ref-value:&lt;/p&gt;&lt;p /&gt;&lt;pre&gt;[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
public object IsDsInsertComment(ref int idComment, string userId, int idPointGroup,....)
{
     :
     idComment = Convert.ToInt32(cmd.ExecuteScalar());
     :
     return idComment;
}&lt;/pre&gt;
&lt;p&gt;The insert to the database works fine as before, however the new value of idComment does not appear in the WebGrid. You can se the webgrid table column defination above. &lt;br /&gt;Here is the ISDataSource defination:&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt; &amp;lt;ISDataSource:ISDataSourceTable 
  ConflictDetection="OverwriteChanges" 
  ParameterOption="FromFields"
  SelectMethod="IsDsGetComments" 
  UpdateMethod="IsDsUpdateComment" 
  InsertMethod="IsDsInsertComment" 
  DeleteMethod="IsDsDeleteComment" 
  TableName="tblComments" 
  TypeName="C2Net.Common.Lbo.LboComment"
  OldValuesParameterFormatString="original_{0}"&amp;gt;
  &amp;lt;SelectParameters&amp;gt;
	&amp;lt;asp:Parameter Name="idPointGroup" Type="Int32" DefaultValue="-1" /&amp;gt;
	&amp;lt;asp:Parameter Name="idBuilding" Type="Int32" DefaultValue = "-1"/&amp;gt;
	&amp;lt;asp:Parameter Name="idOpcGroup" Type="Int32" DefaultValue="-1" /&amp;gt;
	&amp;lt;asp:Parameter Name="from" Type="DateTime" /&amp;gt;
	&amp;lt;asp:Parameter Name="to" Type="DateTime" /&amp;gt;
  &amp;lt;/SelectParameters&amp;gt;
&amp;lt;/ISDataSource:ISDataSourceTable&amp;gt;&lt;/pre&gt;
&lt;p&gt; &lt;span style="font-size: 10pt; "&gt;Regards&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; "&gt;&amp;nbsp; TJ&lt;/span&gt;&lt;/p&gt;
&lt;p /&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p /&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item><item><title>How to get auto-increment column value back into webgrid after insert?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-get-auto-increment-column-value-back-into-webgrid-after-insert/</link><pubDate>Mon, 15 Oct 2012 22:28:50 GMT</pubDate><dc:creator>bernard</dc:creator><description>&lt;p&gt;Hi TJ,&lt;/p&gt;&lt;p&gt;Could I look for your selecting method in ISDataSource? You must handle selection and insertion method if you have identity column in you database. This Knowledge Base maybe will help you to handle retrieving identity value:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.intersoftpt.com/Support/WebGrid/KB/Retrieving-Identity-(Auto-generated-values)-during-Insert-operation-in-WebGrid-Hierarchical-Load-on-Demand-Scenario-using-ISDataSource-NET/"&gt;http://www.intersoftpt.com/Support/WebGrid/KB/Retrieving-Identity-(Auto-generated-values)-during-Insert-operation-in-WebGrid-Hierarchical-Load-on-Demand-Scenario-using-ISDataSource-NET/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Hope this helps.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Bernard&lt;/p&gt;</description></item><item><title>How to get auto-increment column value back into webgrid after insert?</title><link>http://www.intersoftsolutions.com/Community/WebGrid/How-to-get-auto-increment-column-value-back-into-webgrid-after-insert/</link><pubDate>Mon, 15 Oct 2012 06:24:31 GMT</pubDate><dc:creator>throstur62</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;WebUI Studio 2009 R2&lt;/p&gt;
&lt;p&gt;I have a webgrid bound to a ISDataSource (ISD). The ISD has SchemaType="CustomObject" and InsertMethod="InsertComment". That inserts into a database table called "commnts" with it's primary key as id_comment as autoincrement.&lt;br /&gt;&lt;br /&gt;The InsertComment method calls a Stored Procedure in the database that inserts a comment record and returnes the newly inserted id_comment.&lt;br /&gt;&lt;br /&gt;Now I have to somehow get that returned id_comment into the new webgrid row. So I tried setting the  oninserted="ISDataSource1_Inserted" for the ISD:&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt; protected void ISDataSource1_Inserted(object sender,
                                       ISNet.WebUI.DataSource.ISDataSourceStatusEventArgs e)
{&lt;/pre&gt;&lt;pre&gt;   c_webGrid.RootTable.UpdateRowIdentity("idComment", "-1", e.ReturnValue);
}&lt;/pre&gt;
&lt;p&gt; I notice that "&lt;span style="font-size: 10pt; "&gt;e.ReturnValue&lt;/span&gt;&lt;span style="font-size: 10pt; "&gt;" is returning the correct newly inserted id_comment, but this call does unfortunately not update the column of the new row in the grid.&amp;nbsp;&lt;br /&gt;I have also tried using the "DataMember" instead:&lt;/span&gt;&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt;c_webGrid.RootTable.UpdateRowIdentity("id_comment", "-1", e.ReturnValue);&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; "&gt;But that does not help either.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; "&gt;Where can I put in the returned auto-increment id_comment to the web grid column of the newly inserted row, after insert?&lt;br /&gt;&lt;br /&gt;If it helps the SelectMethod of the ISD returns a DataTable from the custom object, one of the columns of the DataTable is id_comment and I have tried to play with all that stuff:&lt;/span&gt;&lt;/p&gt;
&lt;p /&gt;
&lt;p /&gt;&lt;pre&gt;var c = tbl.Columns.Add(Consts.Columns.IdComment, typeof (int));
/*c.AutoIncrement = true;
c.AutoIncrementSeed = 0;
c.AutoIncrementStep = 1;
c.AllowDBNull = false;*/
c.Unique = true;
DataColumn[] pk = new DataColumn[1];
pk[0] = c;
tbl.PrimaryKey = pk;&lt;/pre&gt;
&lt;p&gt; &lt;span style="font-size: 10pt; "&gt;But it did not help.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; "&gt;In the webgrid I specify:&lt;/span&gt;&lt;/p&gt;
&lt;p /&gt;&lt;pre&gt;&amp;lt;RootTable Caption="tblComments" DataKeyField="id_comment"&amp;gt;                         
  &amp;lt;Columns&amp;gt;
    &amp;lt;ISWebGrid:WebGridColumn Caption="ID" 
     DataMember="id_comment" 
     DataType="System.Int32" 
     Name="idComment" 
     EditType="NoEdit" 
     IsAutoIncrement="true" 
     Visible="true" &amp;gt;
     &amp;lt;HeaderStyle HorizontalAlign="Center" /&amp;gt;
     &amp;lt;CellStyle HorizontalAlign="Right" /&amp;gt;
   &amp;lt;/ISWebGrid:WebGridColumn&amp;gt;
   ...
                        &lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p /&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; "&gt;Regards&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: 10pt; "&gt;&amp;nbsp; TJ&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p /&gt;</description></item></channel></rss>