DataAdapter ¶ÔÏóÖеÄSQLÃüÁî
±êÇ©£ºÊý¾Ý·ÃÎÊ ADO.NET
DataAdapter ¶ÔÏóÖеÄSQLÃüÁî ×¢£ºADO.NET¶ÔÏóÄ£ÐÍ ºÍ C# Òª±È SQL ¸üÊʺϴ¦Àí¸´ÔÓÔËËã ºÍ µ¼º½Âß¼£¨±ÈÈ磬²éÕÒÏà¹ØµÄÁíÒ»¸ö±íµÄÊý¾Ý£©
ËùÒÔ£¬¿ÉÒÔ°ÑÊý¾ÝÌî³äµ½DataSetÖУ¬ÔÚ¿Í»§»úÉÏÖ´ÐÐÕâÖÖÂß¼¡£
²é¿´SQL SELECT¡¢UPDATE¡¢INSERT ºÍ DELETEÃüÁ
ÃüÁî¹¹½¨Æ÷(command builder)ÓÃÓÚ¸ù¾ÝSELECTÃüÁîÉú³ÉSQLÃüµÄUPDATE¡¢INSERTºÍDELETE)ÃüÁî¡£
¿ÉÒÔÓÃCommandBuilder¶ÔÏóµÄGetUpdateCommand()¡¢GetInsertCommand()ºÍGetDeleteCommand()·½·¨Éú³ÉÃüÁî¡£
Àý£º
SqlConnection thisConnection = new SqlConnection(@".........ConnectString..........."); thisConnection.Open(); SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT CustomerID from Customers", thisConnection); SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter); //ÓÃCommand builder¹¹½¨ÃüÁî
SqlCommand updateCommand = thisBuilder.GetUpdateCommand();
Console.WriteLine(updateCommand.CommandText); // Êä³öbuilder¹¹½¨µÄSQLÃüÁ¿ÉÒÔ¿´µ½SQLÃüÁîÊÇʲôÑùµÄ£¬
Ïà¹ØÎĵµ£º
1.ijҽԺ²¡·¿¼ÆËã»ú¹ÜÀíÖÐÐèÒªÈçÏÂÐÅÏ¢£º£¨15·Ö£©
¿ÆÊÒ£º¿ÆÃû£¬¿ÆµØÖ·£¬¿Æµç»°
²¡·¿£º²¡·¿ºÅ£¬ËùÊô¿ÆÊÒÃû
Ò½Éú£ºÐÕÃû£¬Ö°³Æ£¬ËùÊô¿ÆÊÒÃû£¬ÄêÁ䣬¹¤×÷Ö¤ºÅ
²¡ÈË£º²¡ÀúºÅ£¬ÐÕÃû£¬ÐÔ±ð£¬Õï¶Ï£¬Ö÷¹ÜÒ½Éú£¬²¡·¿ºÅ£¬ÈëסÈÕÆÚ
ÆäÖУ¬Ò»¸ö¿ÆÊÒÓжà¸ö²¡·¿¡¢¶à¸öÒ½Éú£¬Ò»¸ö²¡·¿Ö»ÄÜÊôÓÚÒ»¸ö¿ÆÊÒ£¬Ò»¸öÒ½ÉúÖ»ÊôÓÚÒ»¸ö¿ÆÊÒ£¬µ«¿É¸º ......
--Ê¡¼¶ Provincial
--³ÇÊÐ City
create table Provincial(pid int,Provincial varchar(50),primary key (pid))
insert into Provincial values(1,'±±¾©ÊÐ')
insert into Provincial values(2,'Ìì½òÊÐ')
insert into Provincial values(3,'ÉϺ£ÊÐ')
insert into Provincial values(4,'Ö ......
--default-character-set=utf8 ÓëÐÞ¸ÄsqlÎļþ¼ÓÈ룺SET NAMES 'utf8';
µ¼Èë½Å±¾Ê±£¬SET NAMES 'xxx' £¬xxxÓ¦¸ÃºÍsql½Å±¾ÎļþµÄʵ¼Ê±àÂëÒ»Ö£¬Èç¹ûÄãÉèÖõÄʱutf-8 £¬ÄÇôÇëÈ·ÈÏÄãµÄsql½Å±¾Îļþʱutf-8±£´æµÄ:
iconv -f UTF-8 xxx.sql
Èç¹ûÏÔʾÕý³££¬ÄÇôÕâÒ»²½¾ÍOKÁË
ÁíÍâ×¢ÒâÄãµÄ½Å±¾ÀÓÐûÓиø¿â±íÉèÖ ......
±¾ÎÄʵÏÖÔÚc#ÖпɸßЧµÄ½«excelÊý¾Ýµ¼Èëµ½sqlserverÊý¾Ý¿âÖÐ,ºÜ¶àÈËͨ¹ýÑ»·À´Æ´½Ósql£¬ÕâÑù×ö²»µ«ÈÝÒ׳ö´í¶øÇÒЧÂʵÍÏ£¬×îºÃµÄ°ì·¨ÊÇʹÓÃbcp£¬Ò²¾ÍÊÇSystem.Data.SqlClient.SqlBulkCopy ÀàÀ´ÊµÏÖ¡£²»µ«Ëٶȿ죬¶øÇÒ´úÂë¼òµ¥£¬ÏÂÃæ²âÊÔ´úÂëµ¼ÈëÒ»¸ö6Íò¶àÌõÊý¾ÝµÄsheet£¬°üÀ¨¶ÁÈ¡£¨È«²¿¶ÁÈ¡±È½ÏÂý£©ÔÚÎҵĿª·¢»·¾³ÖÐÖ»ÐèÒª1 ......
1.
Ä£ºý²éѯЧÂʺܵͣº
ÔÒò£º
like
±¾ÉíЧÂʾͱȽϵͣ¬Ó¦¸Ã¾¡Á¿±ÜÃâ²éѯÌõ¼þʹÓÃ
like
£»¶ÔÓÚ
like ‘%...%’
£¨È«Ä£ºý£©ÕâÑùµÄÌõ¼þ£¬ÊÇÎÞ·¨Ê¹ÓÃË÷ÒýµÄ£¬È«±íɨÃè×ÔȻЧÂʺܵͣ»ÁíÍ⣬ÓÉÓÚÆ¥ÅäËã·¨µÄ¹Øϵ£¬Ä£ºý²éѯµÄ×ֶ㤶ÈÔ½´ó£¬Ä£ºý²éѯЧÂÊÔ½µÍ¡£
½â¾ö°ì· ......