µ÷ÓÃSQL´æ´¢¹ý³Ì
±êÇ©£ºÊý¾Ý·ÃÎÊ ADO.NET
µ÷ÓÃSQL´æ´¢¹ý³Ì ´æ´¢¹ý³ÌÔÚÒ»¸öµ¥ÔªÖзâ×°Á˸´ÔÓµÄSQL²éѯºÍÊý¾Ý¹ý³Ì£¬¿ÉÒÔÓɶà¸ö³ÌÐò»òÓû§Ö®¼äµ÷Óá£
Àý£º
......
SqlConnection thisConnection = new SqlConnection(@"...........ConnectionString..............");
thisConnection.Open();
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandType = CommandType.StoredProcedure; //½«SqlCommand¶ÔÏóµÄÃüÁîÊôÐÔÉèΪ ´æ´¢¹ý³ÌÀàÐÍ¡£
//CommandType.StoreProcedureÊÇADO.NETµÄÒ»¸öö¾Ù
Ïà¹ØÎĵµ£º
ÔÚSQLÓï¾äÖУ¬³£³£Óûá¶Ôʱ¼ä£¨»òÈÕÆÚ£©½øÐÐһЩ´¦Àí£¬ÏÂÃæÊDZȽÏͨÓõÄһЩÓï¾ä£º
ÑÓ³Ù£º
sysdate+(5/24/60/60) ÔÚϵͳʱ¼ä»ù´¡ÉÏÑÓ³Ù5Ãë
sysdate+5/24/60 ÔÚϵͳʱ¼ä»ù´ ......
1.Á¬½ÓÊý¾Ý¿âÎļþ
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;AttachDBFilename=|DataDirectory|TimeTracker.mdf;User Instance=true" />
SqlConnectionStringBuilderʵÀý»¯Ê±£¬ÒªÓõ½connectionString£¬È磺SqlConnectionStringBuild builder = new SqlC ......
Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
WHEN '1' THEN 'ÄÐ'
WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
WHEN sex = '2' THEN 'Å®'
ELSE 'ÆäËû' END
ÕâÁ½ÖÖ·½Ê½£¬¿ÉÒÔʵÏÖÏàͬµÄ¹¦ÄÜ¡£¼òµ¥Caseº¯ÊýµÄд·¨Ïà ......
SQL½ØÈ¡×Ö·û´®
SUBSTRING
·µ»Ø×Ö·û¡¢binary¡¢text »ò image ±í´ïʽµÄÒ»²¿·Ö¡£ÓйؿÉÓë¸Ãº¯ÊýÒ»ÆðʹÓõÄÓÐЧMicrosoft SQL Server Êý¾ÝÀàÐ͵ĸü¶àÐÅÏ¢£¬Çë²Î¼ûÊý¾ÝÀàÐÍ¡£
Óï·¨
SUBSTRING ( expression & ......