IT Community - Software Programming, Web Development and Technical Support

Is it possible to create Stored Procedure in Dataset Using Distinct Key ?

This is a discussion on Is it possible to create Stored Procedure in Dataset Using Distinct Key ? within the ASP and ASP.NET Programming forums, part of the Web Development category; Is it possible to create Stored Procedure in Dataset Using Distinct Key ?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-03-2007, 02:51 AM
KiruthikaSambandam KiruthikaSambandam is offline
D-Web Analyst
 
Join Date: Aug 2007
Posts: 332
KiruthikaSambandam is on a distinguished road
Default Is it possible to create Stored Procedure in Dataset Using Distinct Key ?

Is it possible to create Stored Procedure in Dataset Using Distinct Key ?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-08-2007, 08:03 AM
KiruthikaSambandam KiruthikaSambandam is offline
D-Web Analyst
 
Join Date: Aug 2007
Posts: 332
KiruthikaSambandam is on a distinguished road
Default Re: Is it possible to create Stored Procedure in Dataset Using Distinct Key ?

yeah, i got the answer we can create the stored procedure from the dataset using the distinct, but the restriction in this is we can use the distinct keword for the puticular field, we can only select the distinct records from the dataset using all the fields.

and i found the solution after the getting all the records from the dataset, we can get the distinct records from the purticular fields using the below two functions.

static DataTable SelectDistinct(string ReturnTableName, DataTable SourceTable, string ReturnFieldName, string AdditionalFilterExpression)
{
DataTable dt = new DataTable(ReturnTableName);
dt.Columns.Add(ReturnFieldName, SourceTable.Columns[ReturnFieldName].DataType);
object LastValue = null;
foreach (DataRow dr in SourceTable.Select("", ReturnFieldName))
{
if (LastValue == null || !(ColumnEqual(LastValue, dr[ReturnFieldName])))
{
LastValue = dr[ReturnFieldName];
dt.Rows.Add(new object[] { LastValue });
}
}
if (ds != null)
ds.Tables.Add(dt);
return dt;
}
static bool ColumnEqual(object A, object B)
{
// Compares two values to see if they are equal. Also compares DBNULL.Value.
// Note: If your DataTable contains object fields, then you must extend this
// function to handle them in a meaningful way if you intend to group on them.

if (A == DBNull.Value && B == DBNull.Value) // both are DBNull.Value
return true;
if (A == DBNull.Value || B == DBNull.Value) // only one is DBNull.Value
return false;
return (A.Equals(B)); // value type standard comparison
}


thnx.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure itbarota Database Support 3 03-10-2008 09:43 PM
how to create stored procedure for view to generate xml? poornima ASP and ASP.NET Programming 3 02-25-2008 12:21 AM
Code-behind to create node dynamically using XML File or any Stored Procedure poornima ASP and ASP.NET Programming 3 02-14-2008 09:46 PM
Stored procedure gets executed twice chris ASP and ASP.NET Programming 4 11-01-2007 03:08 AM
Can a stored procedure call itself or recursive stored procedure? How many level SP n H2o Database Support 1 08-03-2007 10:55 AM


All times are GMT -7. The time now is 09:35 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0