Tuesday, March 3, 2009
Use Compare Validator to check your Integers!
<asp:CompareValidator ID="CompareValidatorErrors" ErrorMessage="Please Enter an Integer" Type="Integer" Operator="DataTypeCheck" ControlToValidate="TxtNumberErrors" runat="server"></asp:CompareValidator>
You can specify the ValidationTypeProperty within the Type property to specify (Currency, DateTime, Double, Integer, String) to Compare against.
Monday, December 15, 2008
T-SQL vs. Managed Code
(Choosing Between T-SQL and Managed Code)
From Thiru Thangarathinam over at Developer.com
"When writing stored procedures, triggers, and user-defined functions, programmers now will have to decide whether to use traditional T-SQL or a .NET language such as Visual Basic .NET or C#. The correct decision depends upon the particular situation. In some cases, you should use T-SQL; in others, you should use managed code.
T-SQL is best in situations where the code will mostly perform data access with little or no procedural logic. Managed code is best suited for CPU-intensive functions and procedures that feature complex logic, or where you want to leverage the .NET Framework's Base Class Library. Code placement is another important fact to consider. You can run both T-SQL and in-process managed code on the server. This functionality places code and data close together, and allows you to take advantage of the processing power of the server."
Wednesday, November 19, 2008
Exporting a DataSet to Excel using C#
Just throw a quick LinkButton on your Front End with an OnClick="ExportResults"
Code Behind:
protected void ExportResults(object sender, EventArgs e)
{
string filename = String.Format("Concatenated_Results_{0}_{1}.xls", DateTime.Today.Month.ToString(), DateTime.Today.Year.ToString());
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
Response.Charset = "";
// SetCacheability doesn’t seem to make a difference (see update)
Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
// Throws exception: Control ‘ComputerGrid’ of type ‘GridView’
// must be placed inside a form tag with runat=server.
// ComputerGrid.RenderControl(htmlWrite);
// Alternate to ComputerGrid.RenderControl above
System.Web.UI.HtmlControls.HtmlForm form = new System.Web.UI.HtmlControls.HtmlForm();
Controls.Add(form);
form.Controls.Add(GridResults);
form.RenderControl(htmlWriter);
Response.Write(stringWriter.ToString());
Response.End();
}
