Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

C#Êý¾Ý¿â±à³Ì»ù´¡Ö®sqlÓï¾ä²Ù×÷Êý¾Ý¿âÊý¾Ý

        Á¬½Ósql serverÊý¾Ý¿âÓõ½µÄÃüÃû¿Õ¼äÊÇusing System.Data.SqlClient;
  Êý¾Ý¿âÁ¬½Ó´úÂë:¿ÉÒÔÔÚ´óÀàÖ®ÏÂÉùÃ÷ public SqlConnection myConnection;  //sqlÁ¬½Ó¶ÔÏó
                                    public  SqlCommand myCmd;  //ÓÃÓÚ´æ´¢sqlÓï¾äµÄ¶ÔÏó
        ÁíÒ»ÖÖ¶ÁÈ¡¶ÔÏóÊÇdataset     public SqlDataReader myreader; //ÓÃÓÚ¶ÁÈ¡Êý¾Ý¿âµÄ¶ÔÏó
   SqlConnection myConnection;µÄÓ÷¨ÊÇÔÚÆä¹¹Ô캯ÊýÄÚÖ¸Ã÷Á¬½Ó×Ö·û´®
    myConnection = new SqlConnection("Á¬½Ó×Ö·û´®");
   ¿ÉÒÔÓÃÅäÖÃÎļþÀ´±£´æ¸ÃÁ´½ÓÎļþ,ÕâÑù¼´±ã¸ü»»SQL SERVERÊý¾Ý¿âµÄ·þÎñÆ÷,Ö»ÒªÔÚ½â¾ö·½°¸Àï¸Ä±äÅäÖÃÎļþapp.configÀïµÄÁ¬½Ó×Ö·û´®¾Í¿ÉÒÔÁË¡£¾ßÌåµÄ²Ù×÷ÊÇ:ÔÚVSÖÐË«»÷ÊôÐÔ,ÔÚ³öÏֵĶԻ°¿òÖÐÑ¡"ÉèÖÃ",ÔÚÀïÃæÌîºÃ"Ãû³Æ","ÀàÐÍ","Öµ"¡£Òª¼ÇסÄãÌíµÄÃû³Æ£¨¼ÙÉèΪconnectionstring£©¡£ÔÙÔÚ´úÂëÖÐÉùÃ÷Ò»¸ö×Ö·û´®±äÁ¿str,¸øËû¸³ÖµÎª:Properties.Settings.Default.connectionstring;È»ºó myConnection = new SqlConnection("str"); myConnection.Open(); ¾Í¿ÉÒÔÁ¬½ÓÊý¾Ý¿âÁË¡£
   SqlCommand myCmd; µÄÓ÷¨ÊÇÔÚÆä¹¹Ô캯ÊýÄÚд³ösqlÓï¾äºÍÁ¬½Ó×Ö·û´®¶ÔÏó
    myCmd = new SqlCommand("sqlÓï¾ä",myConnection);
   ÕâÖ»ÊÇ´æ´¢sqlÓï¾ä,»¹Ã»ÓаÑËü½»¸øÊý¾Ý¿â´¦Àí,Òª½»¸øÊý¾Ý¿â´¦Àí¿ÉÒÔÓà myCmd.ExecuteNonQuery();¸Ã·½·¨ÊÇÖ´ÐÐmyCmdÄÚµÄsqlÓï¾ä,²¢·µ»ØintÐ͵ÄÊÜÓ°ÏìµÄÐÐÊý, ¸ü¶àÓõÄÊÇ SqlDataReader myreader¶ÁÈ¡Êý¾Ý¿âµÄ¶ÔÏó.
   SqlDataReader myreader;  Ö»ÄÜͨ¹ýSqlCommand myCmdµÄExecuteReader()´´½¨ÊµÀý Ó÷¨ÊÇ:
   myreader = myCmd.ExecuteReader();  ´´½¨ SqlDataReaderʵÀýµÄͬʱ,ÏòÊý¾Ý¿âÌá½»ÁËsqlÓï¾ä
   ÓÃSELECTÓï¾ä²éѯÊý¾Ýºó¿ÉÒÔÓÃmyreader.Read()À´ÅжÏÊý¾Ý¿âÖÐÓÐûÓÐÒª²éѯµÄÊý¾Ý£¬¸Ã·½·¨·µ»ØµÄÊÇÒ»¸ö²¼¶ûÀàÐÍ,Èç¹ûmyreader.Read()·µ»Øtrue˵Ã÷Êý¾Ý¿âÖÐÓÐÒª²éѯµÄÊý¾Ý,·´Ö®,˵Ã÷Êý¾Ý¿âÖÐûÓÐÒª²éѯµÄÊý¾Ý¡£Èç¹û²éѯ


Ïà¹ØÎĵµ£º

SQL²Ù×÷È«¼¯

ת×ÔCSDNÂÛ̳£ºchaihuoniu
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾ ......

½«Ð¡Ð´½ð¶îת»»ÎªÖÐÎÄ´óдµÄSQLº¯Êý

CREATE FUNCTION [dbo].[f_num_chn] (@num numeric(14,2))
RETURNS varchar(100) WITH ENCRYPTION --¼ÓÃÜ
AS
BEGIN
--°æȨËùÓУºpbsql
  DECLARE @n_data VARCHAR(20),@c_data VARCHAR(100),@n_str VARCHAR(10),@i int
  SET @n_data=RIGHT(SPACE(14)+CAST(CAST(ABS(@num*100) AS bigint) AS varchar(20)), ......

SQLÓï¾äÓÅ»¯¼¼Êõ·ÖÎö

SQLÓï¾äÓÅ»¯¼¼Êõ·ÖÎö
·­Ò룺Jerry [2005-11-11]
Ô­Îijö´¦£ºhttp://www.51testing.com
Ô­ÎÄ×÷Õߣº²»Ïê
תÔØÇë×¢Ã÷£ºÀ´×ÔSawinϵͳ·ÖÎöÖ®´°
²Ù×÷·ûÓÅ»¯
IN ²Ù×÷·û
ÓÃINд³öÀ´µÄSQLµÄÓŵãÊDZȽÏÈÝÒ×д¼°ÇåÎúÒ׶®£¬Õâ±È½ÏÊʺÏÏÖ´úÈí¼þ¿ª·¢µÄ·ç¸ñ¡£
µ«ÊÇÓÃINµÄSQLÐÔÄÜ×ÜÊDZȽϵ͵ģ¬´ÓORACLEÖ´ÐеIJ½ÖèÀ´·ÖÎöÓÃI ......

sql ÖÐ case when Óï·¨

sqlÓïÑÔÖÐÓÐûÓÐÀàËÆCÓïÑÔÖеÄswitch caseµÄÓï¾ä£¿£¿
  ûÓÐ,ÓÃcase   when   À´´úÌæ¾ÍÐÐÁË.   
       
  ÀýÈç,ÏÂÃæµÄÓï¾äÏÔʾÖÐÎÄÄêÔ  
   
  select   getdate()   as   ÈÕÆÚ,case   month(get ......

SQLÖÐÎÄÎÊÅÅÐò

SQLÖÐÎÄÎÊÅÅÐò
    Ê×ÏÈ°ÑÕâЩÐÅÏ¢ÔÚeditplusÖУ¬×ª»»ÎªÒ»ÁУ¬¿½±´µ½excelÖУ¬¿½±´ºó¼Ç×ÅÔÚµÚÒ»ÐÐÇ°²åÈëÒ»ÐУ¬×÷ΪÁбêÍ·£¬ÀýÈçΪname£¬È»ºóÔÚsqlÖбíÖУ¬µ¼ÈëÊý¾Ý£¬Éú³ÉÒ»¸öÐÂ±í£¬ÀýÈçfenlei£¬´ò¿ªsqlÓï¾äÐУ¬Ö´ÐУº
SELECT *
from Fenlei
ORDER BY name COLLATE Chinese_PRC_CS_AS_KS_WS
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ