public bool deleteslabrecord(TSummeryReport deletetsr)
{
EntityManager.TSummeryReports.DeleteOnSubmit(EntityManager.TSummeryReports.Single(theItem=>theItem==deletetsr));
return SaveChanges();
}
Monday, February 28, 2011
Cannot remove an entity that has not been attached.
You will not be able to use attach on a context other then the original context the item was received on unless the entity has been serialized.
Wednesday, February 23, 2011
Merge dynamically create PDF at runtime
I played with this more than 3 days. Finally got the solution.
protected void Button1_Click(object sender, EventArgs e)
{
Guid uniqueid = Guid.NewGuid();
string uniqueidStr = uniqueid.ToString();
int cnt = 0;
string file = Server.MapPath("~/Admin/doc/invoice/Invoice.pdf");
string masterPDfFile = Server.MapPath("~/Admin/doc/invoice/result.pdf");
PdfCopyFields myPdfCopy = new PdfCopyFields(new FileStream(masterPDfFile, FileMode.Create));
while (cnt < 3)
{
PdfReader tmpReader = new PdfReader(file);
string tmpFilePath = Server.MapPath("~/Admin/doc/invoice/" +uniqueidStr+ cnt.ToString() + ".pdf");
FileStream tmppoutputFile = new FileStream(tmpFilePath, FileMode.Create);
PdfStamper tmpoutStamper = new PdfStamper(tmpReader, tmppoutputFile);
AcroFields testform = tmpoutStamper.AcroFields;
testform.SetField("T1","Lasantha");
tmpoutStamper.Close();
PdfReader nwpgReader = new PdfReader(tmpFilePath);
PdfTemplate page = tmpoutStamper.GetImportedPage(nwpgReader, 1);
myPdfCopy.AddDocument(nwpgReader);
cnt += 1;
}
myPdfCopy.Close();
cnt = 0;
while (cnt < 3)
{
string tmpFilePath = Server.MapPath("~/Admin/doc/invoice/" + uniqueidStr+cnt.ToString() + ".pdf");
System.IO.File.Delete(tmpFilePath);
cnt += 1;
}
PdfReader reader = new PdfReader(masterPDfFile);
string resultpath = Server.MapPath("~/Admin/doc/CustomerReports/result.pdf");
FileStream resultstr=new FileStream(resultpath,FileMode.Create);
PdfStamper result = new PdfStamper(reader, resultstr);
result.Close();
reader.Close();
System.IO.File.Delete(masterPDfFile);
}
Get DataTable From Linq query
Here code example
public DataTable ToDataTable(System.Data.Linq.DataContext ctx, object query)
{
if (query == null)
{
throw new ArgumentNullException("query");
}
IDbCommand cmd = ctx.GetCommand(query as IQueryable);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = (SqlCommand)cmd;
DataTable dt = new DataTable("sd");
try
{
cmd.Connection.Open();
adapter.FillSchema(dt, SchemaType.Source);
adapter.Fill(dt);
}
finally
{
cmd.Connection.Close();
}
return dt;
}
Split DataTable in to several DataTables
I achieved this requirement from this code snippet.
public DataTable[] getDataTables(DataTable tableToClone, int seperateVal, int val)
{
DataTable[] tables = new DataTable[val];
int count = 0;
int index = 0;
DataTable copyTable = null;
foreach (DataRow row in tableToClone.Rows)
{
if ((count++ % seperateVal) == 0)
{
copyTable = new DataTable();
copyTable = tableToClone.Clone();
tables[index] = copyTable;
index++;
}
copyTable.ImportRow(row);
}
return tables;
}
Monday, February 14, 2011
Invalid length for a Base-64 char array
This error gave me when i try to encrypt the query string. I solved this issue by http://forums.asp.net/t/1222829.aspx.
It worked fine. But now for some query string values it gives same error. The reason is there was a space character in the query string value. Then i replaced space character with "+". Its working now.
It worked fine. But now for some query string values it gives same error. The reason is there was a space character in the query string value. Then i replaced space character with "+". Its working now.
64-bit encoding does not work well with spaces in the string for some odd reason.
Tuesday, February 8, 2011
Label outside of the update panel is not update when event fire.
Place Label control inside another update panel.
Sunday, February 6, 2011
Subscribe to:
Posts (Atom)
I Built a New Kind of Number Puzzle Game (And You Can Play It Free)
For a long time, I wanted to play a mobile puzzle game that felt genuinely strategic—something that required real brainpower, skipped the a...
-
Microsoft Graph API provides powerful capabilities to interact with Microsoft 365 services. In this guide, we’ll explore how to create calen...
-
When you already have IIS running then you may not be able to run WAMP Server at Localhost. You need to shutdown IIS in order to run WAMP Se...
-
Here a javascript solution for detecting session expire. <html xmlns="http://www.w3.org/1999/xhtml" > <head runat=...