Rich Web client development with ASP.NET ,LINQ , WCF and now Silverlight2

Thursday, September 18, 2008

Linq to SQL SQLMethods

Just came across this really cool Class that contains methods such as Like that allow us to issue SQL Like commands. this is interesting as the T-SQL Like lets us
write statements like select * from table where field like "%john%bill%" . these cannot easily be expressed with Contains. So instead of expressing :
from t in table where field.Contains("nnn");
we would write:
from t in table where SQLMethods.Like(field,"%john%bill%");


there are other interesting methods such as DateTime diff functions.

Silverlight 2 Custom Controls

just put up a new tutorial on creating Silverlight custom controls this is based on an article by Jeff Prosise in MSDN magazine.

http://www.sandkeysoftware.com/silverlight/CustomControls.pdf

Labels:

Saturday, September 06, 2008

capturing Print output from Stored procedure called from Linq to SQL

Recently I have been doing lots of work with calling stored procedures from Linq to SQL. Many of these procs used Print statements as debugging output which was sometimes useful in the development but where not appearing in the output window till we came across this little trick:





// this code goes whereever you instantiate your datacontext e.g constructor in of
// a Dataaccess layer

_Connstr = string.Format("server={0};database={1};user ID={2} ;password={3}", "sqlserver", "table", "user", "password");
_MyDC = new MyDataContext(_Connstr);
SqlConnection conn = _MyDC.Connection as SqlConnection;
// we supply an event handler for the SQL messages
conn.InfoMessage += new SqlInfoMessageEventHandler(conn_InfoMessage);

}
//This fired when the sproc does a output statement like print
static void conn_InfoMessage(object sender, SqlInfoMessageEventArgs e)
{
Console.WriteLine(e.Message);
}