C#²Ù×÷SQL ServerÊý¾Ý¿â(ת)
Visual C#Öж¯Ì¬²Ù×÷SQL ServerÊý¾Ý¿â £¨1£©
·¢²¼Ê±¼ä£º2003.01.14 10:09 À´Ô´£ºÈüµÏÍø ×÷ÕߣºÍõ¿Ã÷
ÔÚ±àдÊý¾Ý¿âÓ¦ÓóÌÐòµÄʱºò£¬ÎÒÃÇ¿ÉÒÔͨ¹ýSQLÓï¾äÀ´¶¯Ì¬´´½¨¡¢ÐÞ¸ÄÊý¾Ý¿âÒÔ¼°ÆäÖеĶÔÏó¡£±¾ÎÄÎÒ¾ÍÏò´ó¼Ò½éÉÜÈçºÎÔËÓÃVisual C#À´¶¯Ì¬²Ù×÷SQL ServerÊý¾Ý¿â£¬ÆäÖаüÀ¨ÈçºÎ´´½¨Ò»¸öSQL ServerÊý¾Ý¿âÒÔ¼°ÈçºÎ´´½¨ÆäÖÐµÄ±í¡¢´æ´¢¹ý³Ì¡¢ÊÓͼ¡¢Ë÷ÒýÖ®ÀàµÄÊý¾Ý¿â¶ÔÏó¡£±¾ÎÄ»¹½éÉÜÁËÈçºÎ¶¯Ì¬µØÐ޸ıíµÄģʽ£¬ÈçºÎ´Ó±í¡¢´æ´¢¹ý³ÌÒÔ¼°ÊÓͼÖжÁÈ¡Êý¾Ý²¢ÏÔʾÔÚÓ¦ÓóÌÐòµÄÊý¾Ý¿â¿Ø¼þÖС£
ÎÒÃÇÖªµÀSQLÓï¾äÔÚ²Ù×÷Êý¾Ý¿âʱÔËÓõÃ×î¶àµÄÊÇSelect¡¢Insert¡¢UpdateºÍDeleteµÈ¶ÔÓÚÊý¾ÝµÄ²Ù×÷£¬¶ø±¾ÎÄÖصãÏò´ó¼Ò½éÉܵÄÊǶÔÓÚÊý¾Ý¿â¼°Æä¶ÔÏóµÄ²Ù×÷¡£Í¨¹ýÕÆÎÕÕâЩ»ù±¾µÄ²Ù×÷·½·¨£¬¶ÁÕ߾ͿÉÒÔ¸ü¼ÓÁé»îµØ½øÐÐÊý¾Ý¿âÓ¦ÓóÌÐòµÄ¿ª·¢¡£
¿ª·¢ÊµÀý¼°²½Öè
1£®½çÃæÉè¼Æ£º
±¾ÎÄÏò´ó¼Ò½éÉÜÒ»¸öÔËÓÃVisual C#¶¯Ì¬²Ù×÷Êý¾Ý¿âµÄʵÀý£¬ÊµÀýµÄ½çÃæÈçͼ1Ëùʾ¡£
ͼ1
´ÓÉÏͼ¿ÉÖª£¬ÎÒÃǵÄʵÀý³ÌÐòÖ»°üº¬ÁË10¸ö°´Å¥¿Ø¼þÒÔ¼°Ò»¸öDataGrid¿Ø¼þ¡£°´Å¥¿Ø¼þ·ÖΪÈýÀà:
µÚÒ»ÀàΪ´´½¨Êý¾Ý¿âÒÔ¼°Êý¾Ý¿â¶ÔÏóµÄ°´Å¥£»
µÚ¶þÀàΪ²é¿´²»Í¬Êý¾Ý¿â¶ÔÏóÖеÄÊý¾ÝµÄ°´Å¥£»
µÚÈýÀàÔòΪÐÞ¸ÄÊý¾Ý¿â¶ÔÏóµÄ°´Å¥¡£ÆäÖеÄDataGrid¿Ø¼þÔòÊÇÓÃÓÚÏÔʾÊý¾ÝµÄ¡£
2£®Ìí¼ÓÒýÓü°Êý¾Ý³ÉÔ±£º
Éè¼ÆÍê½çÃ棬ÎÒÃǾͿÉÒÔ¿ªÊ¼±àд³ÌÐò´úÂë¡£Ê×ÏÈÊÇΪÎÒÃǵijÌÐòÌí¼Ó±ØÒªµÄÒýÓÃÒÔ¼°Ò»Ð©Êý¾Ý³ÉÔ±¡£ÒòΪÎÒÃǵijÌÐòÉæ¼°µ½Êý¾Ý¿âµÄ·ÃÎʲÙ×÷£¬ËùÒÔ±ØÐëÒªÔËÓõ½Êý¾ÝÌṩÕߣ¨Data Provider£©µÄ¶ÔÏó¡£ÔÚ.Net¿ò¼ÜÏ£¬ÎÒÃÇÖ÷ÒªÔËÓõÄÊý¾ÝÌṩÕß·ÖΪÁ½À࣬һÀàÊÇSqlÀàÐ͵ģ¬ÁíÒ»ÀàÊÇOleDbÀàÐ͵ġ£ËüÃÇÉæ¼°µ½µÄÃüÃû¿Õ¼ä·Ö±ðΪSystem.Data.SqlClientºÍSystem.Data.OleDb¡£ÒòΪÎÒÃǵijÌÐò·ÃÎʵÄÊÇSQL ServerÊý¾Ý¿â£¬ËùÒÔÎÒÃÇÔËÓõÄÊý¾ÝÌṩÕ߶ÔÏóӦΪSqlÀàÐ͵ġ£ÔÒòºÜ¼òµ¥£¬¸ÃÀàÐ͵ĶÔÏóÊÇרÃÅΪSQL ServerÊý¾Ý¿â¶øÉè¼ÆµÄ£¬ËùÒÔÐÔÄܵõ½ÁË´ó´óµÄÓÅ»¯¡£ËùÒÔ£¬ÔÚÎÒÃǵijÌÐòµÄ¿ªÊ¼´¦Ìí¼ÓÈçÏÂÒ»¾äÓï¾ä£º
DE>using System.Data.SqlClient;DE>
Ìí¼Ó¶ÔSystem.Data.SqlClientÃüÃû¿Õ¼äµÄÒýÓúó£¬ÎÒÃǽÓÏÂÀ´Îª³ÌÐòÌí¼ÓһЩ±ØÒªµÄÊý¾Ý³ÉÔ±£¬ÕâЩÊý¾Ý³ÉԱΪÎÒÃǵÄÀàµÄ˽ÓгÉÔ±£¬Í¨¹ýËüÃÇÎÒÃÇ¿ÉÒÔÍê³ÉһЩ¶ÔÊý¾Ý¿â¼°Æä¶ÔÏóµÄ²Ù×÷¡£
DE>private string ConnectionString = "Integrated
Security=SSPI;Initial Catalog=;Data Source=localho
Ïà¹ØÎĵµ£º
......
Á¬½ÓAccess
Ê×ÏÈ¿´Ò»¸öÀý×Ó´úÂëƬ¶Ï:
³ÌÐò´úÂë:
--------------------------------------------------------------------------------
using System.Data;
using System.Data.OleDb;
......
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;";
strConnection+=@"Data Source=C:\BegASPNET\Northwind.mdb" ......
ÔÚWin7Ï°²×°SQL2005¿ª·¢°æ£¬°²×°SQL Native ClientʱÌáʾ°²×°Öжϣ¬Ã»ÓÐÔÚÒ⣬ȻºóÔÚ°²×°SQL ServerʱÓÖÌáʾ“[Microsoft][SQL Native Client]¿Í»§¶Ë²»Ö§³Ö¼ÓÃÜ.SQL Server °²×°³ÌÐòÎÞ·¨Á¬½Óµ½Êý¾Ý¿â·þÎñ½øÐзþÎñÆ÷ÅäÖÃ.”жÔØSQL Native ClientÖØа²×°£¬»¹ÊÇÖжϣ¬ÐÞ¸´£¬Ò²Öжϣ¬ÔÙжÔØ£¬ÇåÀí×¢²á±í£¬ÖØ× ......
C#¶ÁÈ¡XML×ÊÁÏ
Ò» C#¶ÁÈ¡XML×ÊÁÏ
À©³ä±ê¼ÇÓïÑÔXML£¨eXtensible Markup Language£©£¬ÊÇÓÉWÈýC»ú¹ØÖƶ©µÄ¡£×öΪÓÃÒÔ´úÌæHTMLÓïÑÔµÄÒ»ÖÖÐÂʽµÄ±ê¼ÇÓïÑÔ£¬XMLÄÚ²¿ÓÐןܶà¸ù±¾»ù×¼£¬XMLÄËÊǾ¹ýÓëÕâЩÏà¸É»ù×¼µØ×éºÏ£¬Ó¦ÓÃÓÚ¿Æѧ¼ÆËã¡¢µç×Ó³ö°æ¡¢¶àýÌåϵÌåÀý×÷ºÍµç×ÓÉÌÎñµÄ¡£C££×÷ΪһÖÖÐÂʽµÄ³ÌÐòÓïÑÔ£¬ÊÇ.Net¹¹¼ÜµÄÒ»¸öÖ ......