Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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˵Ã÷Êý¾Ý¿âÖÐÓÐÒª²éѯµÄÊý¾Ý,·´Ö®,˵Ã÷Êý¾Ý¿âÖÐûÓÐÒª²éѯµÄÊý¾Ý¡£Èç¹û²éѯ


Ïà¹ØÎĵµ£º

PL/SQLÓû§Ö¸ÄÏÓë²Î¿¼ PL/SQLÓ¦ÓóÌÐòÐÔÄܵ÷ÓÅ£¨×ª£©

µÚÊ®¶þÕ PL/SQLÓ¦ÓóÌÐòÐÔÄܵ÷ÓÅ
1¡¢PL/SQLÐÔÄÜÎÊÌâµÄÔµÓÉ
Ó¦»ùÓÚPL/SQLµÄÓ¦ÓóÌÐòÊ©ÐÐЧÂʵÍÏÂʱ£¬Í¨³£ÊÇÒòΪ²»ºÃµÄSQL»°Óï¡¢±à³Ì²½Ö裬¶ÔPL/SQL»ù´¡ÕÆÎÕÔã¸â»òÊÇÂÒÓù²ÏíÄÚ´æ´¢Æ÷´Ù³ÉµÄ¡£
•PL/SQLÖв»ºÃµÄSQL»°Óï
PL/SQL±à³Ì¿´ÉÏÈ¥Ïà¶ÔÕսϼòµ¥£¬ÓÉÓÚËüÃǵĸ´ÔÓÄÚÈݶ¼ÑÚ²ØÔÚSQL»°ÓïÖУ¬SQL»°Óï¾­³£·Öµ£´óÁ¿µÄ ......

SQL ÊÕ²Ø SQL²Ù×÷È«¼¯

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

sqlÓïÑÔÖеÄcase when £¨À´×ÔÎÒ×ð¾´µÄһλÀÏʦСF£©

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

SQL ServerµÄÁ´½Ó·þÎñÆ÷¼¼ÊõС½á

Ò»¡¢Ê¹Óà Microsoft OLE DB Provider For ODBC Á´½ÓMySQL
°²×°MySQLµÄODBCÇý¶¯MyODBC
1¡¢ÎªMySQL½¨Á¢Ò»¸öODBCϵͳÊý¾ÝÔ´£¬ÀýÈ磺ѡÔñÊý¾Ý¿âΪtest ,Êý¾ÝÔ´Ãû³ÆΪ
myDSN
2¡¢½¨Á¢Á´½ÓÊý¾Ý¿â
EXEC sp_addlinkedserver  @server = 'MySQLTest', @srvproduct='MySQL',
@provider = 'MSDASQL', @datasrc = 'myDSN'
......

ʵÏÖÔ¶³ÌÁ¬½ÓSQL Server2005


Ê×ÏÈÅäÖÃSQLSERVER2005£º
´ò¿ª”Microsoft SQL Server Management Studio“Ö±½ÓÓÃWindows Óû§Á¬½Ó½øÈ룬ÔÙÔÚ“°²È«ÐÔ”ÖеēµÇ¼Ãû”Äڵēн¨µÇ¼Ãû”£¬Äã¾Í¶ÔÓ¦µÄÌíºÃ“È·¶¨”¾Í¿ÉÒÔÁË¡£
 
ÔÙÔÚÄã¶ÔÓ¦µÄ“Êý¾Ý¿â”Àï“°²È«ÐÔ&r ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ