convert datatable to generic list in c#
In this blog i'm posting some Asp.net,Sql Server,Jquery,HTML-5,sqlite,C#,JavaScript scripts and sample codes that i found and created by me or my friends with a mind that it Save/ Help our ass some ways...
Showing posts with label Dataset. Show all posts
Showing posts with label Dataset. Show all posts
Tuesday, February 12, 2013
Wednesday, January 30, 2013
Remove Duplicate Row from datatable in c#
As i was also unaware of this feature until i read as answer in fourms.asp.net (link). Previously i was achieved by using lambda expression.Now no need to those just one line code :)
If u had any trouble just ask, Happy to help u :)
Stay Tune... Have a nice day... 'N happy Coding :)
DataTable dt = new
DataTable
{
Columns ={
{"Myid",typeof(int)},
{"Name"},
{"Address"}
}
};
dt.Rows.Add(1, "Arun Aravind",
"Kollam");
dt.Rows.Add(1, "Arun Aravind",
"Kollam");
dt.Rows.Add(2, "Arun Aravind",
"Kollam");
dt.Rows.Add(2, "Arun Aravind",
"Kollam");
dt.Rows.Add(3, "Arun Aravind",
"Kollam");
dt =
dt.DefaultView.ToTable(false, "Address", "Name",
"Myid");
Output
If u had any trouble just ask, Happy to help u :)
Stay Tune... Have a nice day... 'N happy Coding :)
Sunday, December 2, 2012
Count of duplicate record in dataset or datatable
Count of duplicate
record in dataset or datatable in C#
DataTable
dtList = dtduplicate();
DataTable dt = ds.Tables[0];
var result = from c in dt.AsEnumerable()
group c by
new
{
ClientID = c.Field<string>("ClientID"),
CurrentServicerLoanNo
= c.Field<string>("CurrentServicerLoanNo"),
CurrentLoanServicer=c.Field<string>("CurrentLoanServicer"),
NameOfOriginatingLender=c.Field<string>("NameOfOriginatingLender"),
OriginalLoanNumber=c.Field<string>("OriginalLoanNumber")
} into g
where g.Count() > 1
select new
{
g.Key.ClientID,
g.Key.CurrentServicerLoanNo,
g.Key.CurrentLoanServicer,
g.Key.NameOfOriginatingLender,
g.Key.OriginalLoanNumber,
Noofrec = g.Count()
};
for (int i = 0; i <
result.ToList().Count; i++)
{
var item = result.ToList()[i];
// resultTable.Rows.Add(item.ProdId,
item.Pin, item.Noofrec);
dtList.Rows.Add(null,item.ClientID,
item.CurrentLoanServicer, item.CurrentServicerLoanNo,
item.NameOfOriginatingLender, item.Noofrec, item.OriginalLoanNumber);
}
public static DataTable dtduplicate()
{
DataTable dtDuplicatelist = new DataTable();
DataColumn auto = new
DataColumn("AutoID",
typeof(System.Int32));
dtDuplicatelist.Columns.Add(auto);
auto.AutoIncrement = true;
auto.AutoIncrementSeed = 1;
auto.ReadOnly = true;
auto.Unique = true;
dtDuplicatelist.Columns.Add("ClientID",
typeof(string));
dtDuplicatelist.Columns.Add("CurrentLoanServicer",
typeof(string));
dtDuplicatelist.Columns.Add("CurrentServicerLoanNo",
typeof(string));
dtDuplicatelist.Columns.Add("NameOfOriginatingLender",
typeof(string));
dtDuplicatelist.Columns.Add("Noofrec",
typeof(string));
dtDuplicatelist.Columns.Add("OriginalLoanNumber",
typeof(string));
dtDuplicatelist.PrimaryKey = new DataColumn[] { auto }; //
Setting as primary key Then only it will add autoincrement to the Column
return dtDuplicatelist;
}
Stay Tune...
Have a nice day... 'N happy Coding :)
Saturday, December 1, 2012
Dynamically add a new column to dataset or data table in c#
Dynamically add a new
column to dataset or data table in c#
System.Data.DataTable
dtIncremented = ds.Tables[0];
DataColumn auto = new
DataColumn("AutoID",
typeof(System.Int32));
dtIncremented.Columns.Add(auto);
//auto.AutoIncrement = true;
//auto.AutoIncrementSeed = 1;
//auto.ReadOnly = true;
//auto.Unique = true;
// dtIncremented.Columns.Add(auto);
//dtIncremented.PrimaryKey = new DataColumn[] { auto };
dtIncremented.BeginLoadData();
DataTableReader dtReader = new DataTableReader(ds.Tables[0]);
dtIncremented.Load(dtReader);
dtIncremented.EndLoadData();
//foreach (DataRow dr in dtIncremented.Rows)
// {
// dr["AutoID"] =
dtIncremented.Rows.IndexOf(dr);
// }
If u had any trouble just ask, Happy to help u :)
Stay Tune...
Have a nice day... 'N happy Coding :)
Subscribe to:
Posts (Atom)