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 ?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |