Saturday, December 22, 2007
Collection was modified; enumeration operation may not execute
The only way to get around this problem is to use the classic for loop. The resultant code is not as elegant as foreach but anyway works so np :)
Just 1 question doesn't foreach internally execute the classic for loop, then why is classic for loop possible but not foreach
Create SQL Query for all SPs

Tuesday, December 18, 2007
Get the URL of the host from the UserControl
another way is:
public static string GetLocalPath
{
get
{
string path = "~" + HttpContext.Current.Request.Url.LocalPath;
path = path.ToLower();
return path
}
This query can be placed in Global.asax.cs and can be used by both the UserControl and any page.
Saturday, December 15, 2007
IE7 Internet Explorer has stopped working issue
http://petesbloggerama.blogspot.com/2007/02/ie7-vista-internet-explorer-has-stopped.html
Sunday, November 25, 2007
Enable Tracing
Requestlimit = 50 that is it will stop tracing if 50 is over.
The default request limit is 10
Sort a List of Generics using anonymous method
******************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List
Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);
dinosaurs.Add("Tyrannosaurus");
dinosaurs.Add("aAmargasaurus");
dinosaurs.Add("Mamenchisaurs");
dinosaurs.Add("Deinonychus");
dinosaurs.Add("Compsognathus");
Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);
Console.WriteLine("Count: {0}", dinosaurs.Count);
foreach(string dinosaur in dinosaurs)
{
Console.WriteLine("dinosaur before Sort"+dinosaur);
}
dinosaurs.Sort(delegate(string r1, string r2)
{
if(r1.Length == r2.Length)
{
return r1.CompareTo(r2);
}
else{
return r1.Length.CompareTo(r2.Length);
}
});
foreach(string dinosaur in dinosaurs)
{
Console.WriteLine("dinosaur after Sort"+dinosaur);
}
}
}
}
******************************************************************************The most difficult portion to understand was
dinosaurs.Sort(delegate(string r1, string r2)
I really dint understand how r1 and r2 picks up the correct values. The issue is its so randomly picks up values and sometimes r1 == r2
Visual Studio Website and Ajax
Should ASP.NET use Parallel Class?
Stephen Toub: That's sort of two different questions and I'd like to address the first one, which is basically, what does this parallelism stuff have to do with the server? In general, server apps today like ASP.NET, they already have enough parallelism to satisfy the CPUs. So, you take a typical ASP.NET application, it's getting thousands of requests per second, if each of those requests can be isolated, if it's n ot accessing shared state or anything like that, you're already introducing a thousand different asynchronous pieces of work. So, unless you're expecting very few requests into your web server and unless each of those very few requests is doing a ton of computation w o r k , using parallel class, for example, in your server application might not buy you all that much, which ties into your second question. Because, like you say, a lot of stuff is IO-bound in server world and so you take something like asynchronous pages in ASP.NET, it's basically meant to limit the number of thread pool resources you're consuming and maximize your throughput while at the same time basically making sure that you're not blocking other people from requesting your server resources just because you're waiting for the database to come back or you're waiting for a web service call to return or something like that. So, a lot of the technologies that we're working on right now, we're focusing largely at desktop or at backend data processing, not so much at the web server world because for the most part your frontend web applications have enough concurrency to go around.
Taken from Parallel Programming with .net Hanselminutes
Amdah's Law
Taken from Parallel Programming with .net Hanselminutes
Optimal Threads in one Processor is one assuming that its is a CPU operation
Taken from Parallel Programming with .net Hanselminutes
Process and Processor
Stephen Toub: Only if you want it to. You'd actually have to express that either as the user in, for example, Task Manager or as a developing setting thread affinity and process affinity for particular processors, but by default, no. There is no affinity. If you have a process that uses only one thread, by default, that process will ever only be running on one processor at a time, but it can certainly move around from processor to processor. Ideally, it won't for a lot
of subtle reasons like making sure that caches aren't invalidated and the memory that the -- well, that
caches aren't invalidated is good enough, but if the process has in it multiple threads and let's say in your case it has four threads, each of those four threads can be running one on each processor at the same time.
Scott Hanselman: Who decides that?
Stephen Toub: For the most part, it's t h e operating system unless as a developer you go ahead and say, "This thread here, I really want to tie to processor 3," in which case you can set an affinity mask that says, "Never let the operating system only allow this thread to run on processor 3 and if processor 4 is available and there's absolutely nothing happening on it, sorry, you can't run this thread until processor 3 is available."
Taken from Parallel Programming with .net Hanselminutes
Control State in GridView
edit index, page index, selected index, sort expression, sort direction and data key names and values. So here even if you clear the ViewState these states still persist
Serializable is non-inherited
Issue with inline sql
There is yet another issue which is maintainability a DB guy changes some schema and he usually looks into all the DB Objects like SPs and functions but will never look into the .NET code. Everybody will come to know abut the issue only when the code breaks.
adv of Clone in .net
So if Obj A is copied by Obj B and say after sometime some values in Obj A changes then Obj B also changes.
If we clone its called “shallow copying” and the above issue will not occur.
Back Button and SessionSate
So it’s always worthwhile to load the page again using some means (like have a session state from the current page to the prev page and then loading the prev page afresh)
Tuesday, November 6, 2007
Cannot use SQLServer Destination when the SQLServer is not Local
In other words if we are trying to run SSIS remotely then use OLE DB as destination even if
The destination is SQL Server.
Thursday, October 18, 2007
Into a Dev Project
But I somehow dont like this S/W job.
ShouldI become a lecturer?
Wednesday, September 26, 2007
Into a Support Project
I am an ASP.NET developer and now I’m put in a support project which has nothing to do with .net.
I’m fighting hard with my managers but in vain, I may end up my next 6 months here L
Need to think what to make out of this opportunity (/threat)
I’ve to rethink what I really want in my life and have to have the action plan for that
Saturday, September 8, 2007
Get the previous page name:
{
string sPageName = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
Response.Write("sPageName"+sPageName); }
Properties and OOPS
How to check whether the coding is really oops oriented?
Check whether all the methods created in the class can exist as static, if yes then the coding is not in oops methodology.
Manipulate DataTable in a GridView
GridVIew make Column Invisible
but when u access it in C# the Text of this cell will be empty.
The Text can be accessed only when the Cell is Visible
To get around this problem make the cell as Visible = false in Row_Created event in C#
Even this does not work I get index out of bound exception
The way out is the following code:
listtaskGridView.DataSource = ListTaskDS;
listtaskGridView.DataBind();
listtaskGridView.Columns[0].Visible = false;
listtaskGridView.Columns[7].Visible = false; listtaskGridView.Columns[8].Visible = false;
GridView accessing Columns Issue
When u bind the DataSource the only way to access GridView is thru its row only
Also I don’t like the way Cells are behaving in Row
I cannot give ColumnName in the cell
i.e., e.Row.Cells["AssignedAdm"] will not work
u even don’t have the facility to lookup the cell’s header like
e.Rows.Cells[0].Caption or e.Rows.Cells[0].HeaderText
The only way to get around the problem is remembering the cell index. The other way out is to get the GridView’s 1st row and get the Cell.Text which is the header and remember the index.
Dynamic Controls in GridView
The Below Link has the details:
http://community.strongcoders.com/blogs/ryan/archive/2005/12/01/gridview-dynamic-button-frustrations.aspx
I faced similar issue as well and have to content with a Button in the aspx page to get around this problem
After sometime I understand the issue is u add anything dynamically to GridView’s Footer (or any other rows) after DataBound then u deem to loose it.
A heavy solution is available in the following url need to fully understand the code.http://www.codeproject.com/useritems/GridView_with_insert_line.asp
Change in strategy
I've taken some notes in my work which I'm going to paste here.
Many of these posts will be abstract and would not be complete.
But anyway if I don't do this then I would not be able to record anything.
So the Strategy is changed now:
Log all the things which u wish to log (even if they are incoherent)
Thursday, July 26, 2007
Table Valued Split Function
I thoroughly enjoyed using this Split function throughout my SPs and functions.
Dynamic Query cannot be used in Functions and I’d a requirement to write a table valued function which has to parse a variable number of Items.
I got around the problem by using the Split function in it.
This is what I did:
Send the list of ItemIds as a comma separated string
Parse it using the Split function inside the Table Valued function.
The Split Function code goes like this:
CREATE FUNCTION [dbo].[Split](@List nvarchar(2000), @SplitOn
nvarchar(5))
RETURNS @RtnValue TABLE (Id INT
IDENTITY(1,1), Value NVARCHAR(100))
AS
BEGIN
WHILE (CHARINDEX(@SplitOn,@List)>0)
BEGIN
INSERT INTO @RtnValue
(value)
SELECT Value =
LTRIM(RTRIM(SUBSTRING(@List,1,CHARINDEX(@SplitOn,@List)-1)));
SET @List =
SUBSTRING(@List,CHARINDEX(@SplitOn,@List)+LEN(@SplitOn),LEN(@List));
END
INSERT INTO @RtnValue (Value) SELECT Value =
LTRIM(RTRIM(@List));
RETURN;
END
Courtesy: to the unknown Internet site that hosted it and to the unknown developer who created it.
Agreed that this function has limitation like you cannot parse a very big string since the Value column’s limit is 100.
But still this Split function is very useful!!
Tuesday, July 24, 2007
Grouping in Infragistics Excel
using System;
using System.Collections.Generic;
using System.Text;
using Infragistics.Excel;
namespace ConsoleApplication1{
class Program
{
static void Main(string[] args)
{
Workbook theWorkBook = new
Workbook();
Worksheet
theWorkSheet;
theWorkSheet =
theWorkBook.Worksheets.Add("Customers");
theWorkSheet.Rows[0].OutlineLevel =
0;
//the outline property is the key to Grouping
theWorkSheet.Rows[0].Cells[0].Value =
"hello";
theWorkSheet.Rows[1].OutlineLevel = 1;
theWorkSheet.Rows[1].Cells[0].Value =
"hello1";
theWorkSheet.Rows[2].OutlineLevel =
2;
theWorkSheet.Rows[2].Cells[0].Value =
"hello2";
theWorkSheet.Rows[2].Expanded =
false;
theWorkSheet.Rows[1].Expanded =
false;
BIFF8Writer.WriteWorkbookToFile(theWorkBook,
"C://file.xls");
}
}
}
Thursday, July 12, 2007
Excel Export for Multi-Header UltraGrid
If the UltraWebGrid has multi-header then UltraWebGridExcelExporter doesnot export the Grid properly. The only way to get around the problem is to create a custom method to write the Grid data in xls format.
One way of doing this is by using StringBuilder to create html table and then passing it as a response. The Column and Rowspacing can be achieved using RowSpan and ColumnSpan of Table Header
Friday, July 6, 2007
Multi header implementation in UltraWebGrid
So how to do it:
- Mostly if we are going for Multi column header then there should be some static Columns
- So first write the code to Bind the DataSet
- Use Initialize Layout Event to write the Static Columns and also to work on the Spanning of the columns.
Sample Code
public void UltraWebGrid1_InitializeLayout(object sender,
Infragistics.WebUI.UltraWebGrid.LayoutEventArgs e)
{
// Create Static UltraGrid Header
Infragistics.WebUI.UltraWebGrid.ColumnHeader ch = new
ColumnHeader(true);
// other Code
// .......
// Initilaize the Spans here
ch.RowLayoutColumnInfo.OriginY = 0;
ch.RowLayoutColumnInfo.OriginX = 0;
ch.RowLayoutColumnInfo.SpanX = 2;
ch.RowLayoutColumnInfo.SpanY = 1;
// other Codes
}
The Methods Span X, OriginX are self explanatory, but what is important is to visualize how the axis is getting created in UltraWebGrid. This is shown in the dig above.
One more thing to note is correct calculation of the Spans and Origins of each header is critical.
If you get it wrong then
- The Headers may be scrambled
- Some Headers may be lost
Note that no error Will be thrown on either of the case so write the Origin and Spanning of the columns carefully
The Story Behind
I was new to .net and Infragistics and one requirement came up to construct a Grid using Multi-Header. I know for sure that this will be possible using Infragistics but don't know how exactly to do it. I tried a lot of googling but in vain. Finally I got a Chinese web site which talked about this :)
That was a wake up call for me, I thought how many ppl would've searched for this implementation and would've suffered?
I decided then that I should write a Blog about this and other things which I know and assume many ppl do not know. May be a guy reading this implementation might think its silly to do it in the way i wrote and can come back with a better approach. Or may be I'm duplicating a thing which would've been already known to many ppl. If my consciousness says to share something then I will definitely share it.
Table Dependency Issue
SELECT OBJECT_NAME(id) FROM syscomments WHERE [text] LIKE '%Table1%' AND OBJECTPROPERTY(id, 'IsProcedure') = 1 GROUP BY OBJECT_NAME(id)