c# SQLÊý¾Ý¿âÔ¶³ÌÁ¬½Ó¼°ÅäÖ÷½·¨
c# SQLÊý¾Ý¿âÔ¶³ÌÁ¬½Ó¼°ÅäÖ÷½·¨
Ò»£ºC# Á¬½ÓSQLÊý¾Ý¿â
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
Server=myServerName\theInstanceName;Database=myDataBase;Trusted_Connection=True;
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
1£ºIntegrated Security²ÎÊý
µ±ÉèÖÃIntegrated SecurityΪ True µÄʱºò£¬Á¬½ÓÓï¾äÇ°ÃæµÄ UserID, PW ÊDz»Æð×÷Óõģ¬¼´²ÉÓÃwindowsÉí·ÝÑé֤ģʽ¡£
Ö»ÓÐÉèÖÃΪ False »òÊ¡ÂÔ¸ÃÏîµÄʱºò£¬²Å°´ÕÕ UserID, PW À´Á¬½Ó¡£
Integrated Security »¹¿ÉÒÔÉèÖÃΪ£ºsspi £¬Ï൱ÓÚ True£¬½¨ÒéÓÃÕâ¸ö´úÌæ True¡£
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=true;
Data Source=myServerAddress;Initial Catalog=myDataBase;;User ID=myUsername;Password=myPasswordIntegrated Security=false;
2£º²ÎÊýTrusted_Connection
Trusted_Connection=true£¬½«Ê¹Óõ±Ç°µÄ Windows ÕÊ»§Æ¾¾Ý½øÐÐÉí·ÝÑéÖ¤
Trusted_Connection=false;½«²»²ÉÓÃÐÅÈÎÁ¬½Ó·½Ê½(Ò²¼´²»²ÉÓÃWindowsÑéÖ¤·½Ê½)£¬¶ø¸ÄÓÉSQL Server 2000ÑéÖ¤·½Ê½
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=false;
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
3£ºInitial CatalogÊÇÄãÒªÁ¬½ÓµÄÊý¾Ý¿âµÄÃû×Ö
4£ºWINCEÁ¬½Ó
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;User ID=myDomain\myUsername;Password=myPassword;
¶þ£º¿ÉÒÔÀûÓÃSqlConn
Ïà¹ØÎĵµ£º
SQL×¢Èë¹¥»÷µÄΣº¦ÐԺܴó¡£ÔÚ½²½âÆä·ÀÖ¹°ì·¨Ö®Ç°£¬Êý¾Ý¿â¹ÜÀíÔ±ÓбØÒªÏÈÁ˽âÒ»ÏÂÆä¹¥»÷µÄÔÀí¡£ÕâÓÐÀûÓÚ¹ÜÀíÔ±²ÉÈ¡ÓÐÕë¶ÔÐԵķÀÖδëÊ©¡£
¡¡ Ò»¡¢ SQL×¢Èë¹¥»÷µÄ¼òµ¥Ê¾Àý¡£
¡¡¡¡statement := "SELECT * from Users WHERE Value= " + a_variable + "
ÉÏÃæÕâÌõÓï¾äÊǺÜÆ ......
×î½üºÜ棬ÓиöÏîÄ¿ÂíÉÏÒªÕб꣬һ¸öÏîÄ¿µÈ׏¤£¬Èô¸ÉËöËéµÄʽøÐÐÖУ¬ÓÐÒ»¶Îʱ¼äû¸üÐÂЩÓÐÓªÑøµÄ¶«Î÷ÁË
˵¸öÌâÍâ»°ÏÈ¡£
½ñÌ쿪»ú×¼±¸°Ñ×òÌìµÄ¶«Î÷debugһϣ¬ºÜÏ°¹ßµØÓÒ¼üÏîÄ¿µÄÆô¶¯Îļþ¿ªÊ¼debug£¬»úÆ÷ͻȻÀ¶ÆÁÖØÆô¡£¿ªÊ¼ÒÔΪÓÖÊÇÄÚ´æÔÚ͵͵³¬Æµ£¬¼ì²éÁËÒ»ÏÂbios£¬·¢ÏÖûʲôÎÊÌ⣬ҲûÔõôÔÚÒ⣬ËíÖØпªÆôvs2008¼ÌÐø ......
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
¡¡¡¡DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
¡¡¡¡DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
¡¡¡¡Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
¡¡¡¡1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
¡¡¡¡2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database ......