How to run code from sql server in c# SqlCommand cmd = new SqlCommand(“select Developer from Stackoverflow where UserID=’786′ and Developer=’Sufiyan'”, con); if (con.State == ConnectionState.Closed) { con.Open(); } SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { string codeSnippet = reader[“CodeSnippet”].ToString(); dynamic script = CSScript.LoadCode(@” using System; using System.Windows.Forms; using System.Collections.Generic; using System.Data; using System.Windows.Forms; using System.Data.SqlClient; public class RunFromSqlServer {… Read more →
OData Paging
Usage: using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net.Http; using System.Web.Http; using System.Web.Http.OData.Query; namespace WebApiTest.Controllers { public class ValuesController : ApiController { private const int PAGESIZE = 25; // GET api/values [ActionName(“Default”)] public PageOfResults Get(ODataQueryOptions queryOptions) { var data = new Poco[] { new Poco() { id = 1, name = “one”, type = “a” }, new Poco()… Read more →
a debuggable/installable windows service template: Part 1 Part 2 Minor amendment: Program.cs catch (Exception ex) { ConsoleHarness.WriteToConsole(ConsoleColor.Red, “An exception occurred in Main(): {0}”, ex); if (Environment.UserInteractive) { Console.ReadKey(); } } Read more →
3 column layout
3 column layout <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”> <html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en-GB”> <head> <title>The Perfect 3 Column Liquid Layout</title> <link rel=”stylesheet” type=”text/css” href=”screen.css” media=”screen” /> </head> <body> <div id=”header”> </div> <div class=”colmask threecol”> <div class=”colmid”> <div class=”colleft”> <div class=”col1″> <!– Column 1 start –> <p>centre stuff</p> <!– Column 1 end –> </div> <div class=”col2″> <!– Column 2 start… Read more →
type safe enum extensions for MVC
extension method public static class EnumSelectList { public static IEnumerable GetList(this T thing) where T : IEnumerable { var result = from i in thing select new SelectListItem { Text = i.Value }; return result; } } new method on the type public static IEnumerable GetAll() { var list = ( from i in _instances select i.Value) .Cast(); return list;… Read more →
How to log-in to your WordPress site
yoursite\wp-admin Read more →
Deserialize this / Deserialize inside of the instance
Type type = this.GetType(); PropertyInfo[] properties = type.GetProperties(); reader.Read(); while (reader.Read()) { PropertyInfo property = properties.GetPropertyByXmlElement(reader.Name); if (property != null) { property.SetValue(this, reader.ReadElementContentAs(property.PropertyType, null)); } } this is the extension method `GetPropertyByXmlElement(string)` public static PropertyInfo GetPropertyByXmlElement(this PropertyInfo[] properties, string name) { XmlElementAttribute attr = new XmlElementAttribute(name); PropertyInfo property = ( from p in properties where p.GetCustomAttributes().Any(a => a.Equals(attr)) select p)… Read more →
Test ORACLE directory permissions
declare file_handle utl_file.file_type; begin file_handle := utl_file.FOpen(‘DIRECTORY_NAME’, ‘test.txt’, ‘w’); utl_file.put_line(file_handle, ‘test’); utl_file.FFlush(file_handle); utl_file.FClose(file_handle); end; Read more →
Connecting to Data in Telerik Reporting with the ObjectDataSource Component
Connecting to Data in Telerik Reporting with the ObjectDataSource Component Read more →
My 3 Favorite Connection String Tips
My 3 Favorite Connection String Tips Read more →