In SQL Server I often do a SELECT TOP 10 FROM [TableName].
To get the bottom ten I found that I could ORDER BY DESC.
In Oracle things are a bit different. In Oracle they have a ROWNUM system field. To get the first ten records you just have to get the ROWNUMs that are 10 and below like the following:
SELECT * FROM [TableName] WHERE ROWNUM >= 11
Thursday, March 13, 2014
Control 'gv' of type 'GridView' must be placed inside a form tag with runat=server.
I have gotten this error several times:
Control 'gv' of type 'GridView' must be placed inside a form tag with runat=server.
Each time I forget the solution and after I fix it I eventually forget why I was getting it. This time is not different. I can't remember why it started happening, but the solution is to create a method like this.
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
Sometimes & nbsp; Doesn't Work and I Have to Use & #160; Instead
I found recently that sometimes when I use an HTML & nbsp; it literally prints & nbsp; instead of a nonbreaking space.
Blogger is having trouble taking what I want to say, so I have to put a space between the ampersand and the nbsp; characters to get it to print correctly.
One instance that gave me trouble with the nbsp was between a td tag, even though I can include other HTML markup in between the opening and closing tag.
After some head scratching and reading I tried using a & #160; and that worked.
I guess HTML has two different ways of expressing non breaking spaces.
Blogger is having trouble taking what I want to say, so I have to put a space between the ampersand and the nbsp; characters to get it to print correctly.
One instance that gave me trouble with the nbsp was between a td tag, even though I can include other HTML markup in between the opening and closing tag.
After some head scratching and reading I tried using a & #160; and that worked.
I guess HTML has two different ways of expressing non breaking spaces.
Thursday, February 6, 2014
ASP.Net Web Forms Application Can't Find Namespace
I was creating a test Web Forms application and added some existing code files.
I first added them to the app_code folder, but in there they could not find the OracleDataClient namespace. I found something that said to move the code file out of app_code and that fixed the Oracle problem.
Then when I would reference classes in those files the page code did not recognize the namespace.
After a while of searching I found someone who said to right click on the files and view properties.
The property they said to look at was Build Action. My file was set to Content and I saw to change it to Compile. That fixed it.
I first added them to the app_code folder, but in there they could not find the OracleDataClient namespace. I found something that said to move the code file out of app_code and that fixed the Oracle problem.
Then when I would reference classes in those files the page code did not recognize the namespace.
After a while of searching I found someone who said to right click on the files and view properties.
The property they said to look at was Build Action. My file was set to Content and I saw to change it to Compile. That fixed it.
Wednesday, January 15, 2014
DataReader Problems Boxing and Unboxing
After I researched the problems and implemented the solutions in this post http://brookssoftwaredev.blogspot.com/2014/01/net-datareader-not-closing-connection.html I found that I was still getting timeouts while trying to obtain a connection from the pool.
I researched more and found that doing normal conversion like
int.Parse(reader["FieldName"]);
caused boxing and unboxing of the values. I was doing this on several values for many records.
I did some research and found that the boxing and unboxing causes the garbage collector to bog down. I found that the DataReader has special methods to avoid the boxing and unboxing. These methods are things like GetChar, GetDouble, GetDateTime, and GetInt32. From what I read these stop the boxing and unboxing and prevent the garbage collector from thrashing.
Once I implemented those methods my timeouts on the connection pool went away. It appears as though the garbage collector couldn't clean up the connections, since it was busy with all of the rogue objected from the DataReader boxing and unboxing.
I realized that using a DataReader left the connection open and there needed to be precautions taken, but there are several other things that you must deal with when using a DataReader, so use caution.
I researched more and found that doing normal conversion like
int.Parse(reader["FieldName"]);
caused boxing and unboxing of the values. I was doing this on several values for many records.
I did some research and found that the boxing and unboxing causes the garbage collector to bog down. I found that the DataReader has special methods to avoid the boxing and unboxing. These methods are things like GetChar, GetDouble, GetDateTime, and GetInt32. From what I read these stop the boxing and unboxing and prevent the garbage collector from thrashing.
Once I implemented those methods my timeouts on the connection pool went away. It appears as though the garbage collector couldn't clean up the connections, since it was busy with all of the rogue objected from the DataReader boxing and unboxing.
I realized that using a DataReader left the connection open and there needed to be precautions taken, but there are several other things that you must deal with when using a DataReader, so use caution.
Saturday, January 11, 2014
.Net DataReader Not Closing Connection After Closed
As I research using the .Net DataReader I kept seeing information online that said things like "When the command is executed, the associated Connection object is closed when the associated DataReader object is closed."
There had been concerns that the data reader would tie up the connection too long. There was also concern that we were closing the connection explicitly, especially since the creation of the reader was abstracted into another class. The class using the reader would not have access to the command or connection that created it.
In various different places I have worked we have used this and were confident that the DataReader would clean itself and its connection up, based upon what we had read.
We did a small test page recently and it turns out that by default it leaves the connection open.
We opened a connection and created a command tied to that connection and then used that command to create a DataReader. We did command.ExecuteReader() to create the reader.
As we researched further we found that ExecuteReader has an optional parameter of a CommandBehavior enumeration. If you pass CommandBehavior.CloseConnection then it closes the connection when the reader closes.
There had been concerns that the data reader would tie up the connection too long. There was also concern that we were closing the connection explicitly, especially since the creation of the reader was abstracted into another class. The class using the reader would not have access to the command or connection that created it.
In various different places I have worked we have used this and were confident that the DataReader would clean itself and its connection up, based upon what we had read.
We did a small test page recently and it turns out that by default it leaves the connection open.
We opened a connection and created a command tied to that connection and then used that command to create a DataReader. We did command.ExecuteReader() to create the reader.
As we researched further we found that ExecuteReader has an optional parameter of a CommandBehavior enumeration. If you pass CommandBehavior.CloseConnection then it closes the connection when the reader closes.
Thursday, September 26, 2013
Dynamically Created Control Not Firing Events in ASP.Net
I have an aspx page where when someone changes the value in a Drop Down List the database is queried and records are displayed in an HTML table. As the table is created I add a Button control to each row. I have tried this with a CheckBox as well with similar results. I also wire up a click event for each button when it is created. All the events for the Buttons point to the same event.
The grid is created properly, with the button on each line. When I click one of the buttons the Page_Load event fires, but the click event does not.
When I dynamically create a button outside the grid from the Drop Down List's SelectedIndexChanged event it also does not fire the click event.
When I move the button creation code to the Page_Load event wrapped in an If (!IsPostback) block the Click event works properly.
It appears that if the control is not created in Form_Load or Form_Init the dynamic control's events do not fire. I have not found a solution to be able to do what I want, but I thought what I found in my research so far might be useful to someone.
The grid is created properly, with the button on each line. When I click one of the buttons the Page_Load event fires, but the click event does not.
When I dynamically create a button outside the grid from the Drop Down List's SelectedIndexChanged event it also does not fire the click event.
When I move the button creation code to the Page_Load event wrapped in an If (!IsPostback) block the Click event works properly.
It appears that if the control is not created in Form_Load or Form_Init the dynamic control's events do not fire. I have not found a solution to be able to do what I want, but I thought what I found in my research so far might be useful to someone.
Subscribe to:
Posts (Atom)