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

ÉîÈëÑо¿SQL SERVER 2005ºÍ¶à»î¶¯½á¹û¼¯£¨MARS£©

SQL SERVER 2005ÒýÈëÁËÔÚµ¥Ò»Á¬½ÓÉ϶Զà»î¶¯½á¹û¼¯£¨Ò²³ÆΪMARS£©»ò¶à¸öÇëÇóµÄÖ§³Ö¡£Í¨¹ýÔÚÓëSQL SERVER 2005µÄÁ¬½ÓÉÏÆôÓÃÕâÒ»ÌØÐÔ£¬µ±´æÔÚÓëSqlconnectionÏà¹ØÁªµÄ¿ª·ÅʽSqlDataReaderʱ£¬Á¬½Ó½«²»»áÖжϡ£¼´Ê¹ÉÐδ¹Ø±Õµ±Ç°´ò¿ªµÄSqlDataReader£¬Ò²ÈÔÈ»Äܹ»ÔÚSqlconnectionÉÏÖ´ÐÐÆäËû²éѯ±ÈÈ磺SELECT£¬UPDATE£¬CREATETABLEµÈµÈ¡£
¾Ù¸ö¼òµ¥µÄÀý×Ó£¬¾ÍÊÇÔÚNorthwindÊý¾Ý¿âÀïµÄ¶©µ¥±íÀïÈ¡¶©µ¥Êý¾Ý£¬¶øÇҰѶÔÓ¦µÄ×Ó¶©µ¥Ã÷ϸÊý¾ÝÒ»ÆðÈ¡³ö¡£
C#ʾÀý´úÂ룺<¼¤¹â´«Õæ»ú>
string strSQL;
SqlConnectionStringBuilder ssb = new SqlConnectionStringBuilder();
ssb.DataSource = ".";
ssb.InitialCatalog = "Northwind";
ssb.UserID = "sa";
ssb.Password = "********";
ssb.MultipleActiveResultSets = true;
SqlConnection cn = new SqlConnection(ssb.ConnectionString);
SqlCommand cmdOrders, cmdDetials;
SqlParameter pCustID, pOrderID;
SqlDataReader rdrOrders, rdrDetials;
cn.Open();
strSQL = "SELECT OrderID,OrderDate from Orders WHERE CustomerID = @CustomerID";
cmdOrders = new SqlCommand(strSQL, cn);
pCustID = cmdOrders.Parameters.Add("@CustomerID", SqlDbType.NChar, 5);
strSQL = "SELECT ProductID,Quantity,UnitPrice from [ORDER dETAiLS] WHERE OrderID = @OrderID";
cmdDetials = new SqlCommand(strSQL, cn);
pOrderID = cmdDetials.Parameters.Add("@OrderID", SqlDbType.NChar, 5);
pCustID.Value = "ALFKI";
Console.WriteLine("Orders for {0}", pCustID.Value);
Console.WriteLine("=================");
rdrOrders = cmdOrders.ExecuteReader();
while (rdrOrders.Read())
{
Console.WriteLine("OrderID: {0} OrderDate:{1:d}", rdrOrders["OrderID"], rdrOrders["OrderDate"]);
pOrderID.Value = rdrOrders["OrderID"];
rdrDetials = cmdDetials.ExecuteReader();
while (rdrDetials.Read())


Ïà¹ØÎĵµ£º

C# Ö´ÐÐSQLÊÂÎñʵÀý´úÂë

 [C#]
public void RunSqlTransaction(string myConnString)
{
    SqlConnection myConnection = new SqlConnection(myConnString);
    myConnection.Open();
    SqlCommand myCommand = myConnection.CreateCommand();
    SqlTransaction m ......

SQLÏÂÈÕÆÚº¯ÊýʹÓÃ

ÕâÁ½Ììдһ¸öºÍͳ¼ÆÊý¾ÝÓйصĴ洢¹ý³Ì£¬ÀïÃæÒªÀûÓÃÈÕÆÚ½øÐÐһЩ¼ÆËãºÍÅжϣ¬Ò²×ÔȻҪÀûÓÃSQLµÄһЩÈÕÆÚÏà¹ØµÄº¯Êý¡£ÕâÀïÂÔ¼Çһϣ¬µ±ÊǸ´Ï°Ò»ÏÂSQL¡£
ÀûÓÃSQL½Å±¾ÄÚÖõļ¸¸öº¯Êý£¬ÎÒÃÇÄÜÁé»îµÄ¶ÔÈÕÆÚ½øÐмÆËãºÍ±È½Ï¡£³£Óõļ¸¸öº¯Êý£ºGETDATE(),DATEDIFF(),DATEADD()
GETDATE() µ±È»¹ËÃû˼Ò壬µÃµ½µ±Ç°µÄÈÕÆÚ£¬·µ»ØÀàÐÍÊ ......

¼¸Ìõ³£¼ûµÄÊý¾Ý¿â·ÖÒ³ SQL Óï¾ä

 ÎÒÃÇÔÚ±àдMISϵͳºÍWebÓ¦ÓóÌÐòµÈϵͳʱ£¬¶¼Éæ¼°µ½ÓëÊý¾Ý¿âµÄ½»»¥£¬Èç¹ûÊý¾Ý¿âÖÐÊý¾ÝÁ¿ºÜ´óµÄ»°£¬Ò»´Î¼ìË÷ËùÓеļǼ£¬»áÕ¼ÓÃϵͳºÜ´óµÄ×ÊÔ´£¬Òò´ËÎÒÃdz£³£²ÉÓã¬ÐèÒª¶àÉÙÊý¾Ý¾ÍÖ»´ÓÊý¾Ý¿âÖÐÈ¡¶àÉÙÌõ¼Ç¼£¬¼´²ÉÓ÷ÖÒ³Óï¾ä¡£¸ù¾Ý×Ô¼ºÊ¹ÓùýµÄÄÚÈÝ£¬°Ñ³£¼ûÊý¾Ý¿âSQL Server,OracleºÍMySQLµÄ·ÖÒ³Óï¾ä£¬´ÓÊý¾Ý¿â±íÖÐµÄµÚ ......

ÔÚSQL ServerÓ¦ÓÃÖÐʹÓÃOUTPUT×Ó¾ä

 ÏÖÔÚ´ó¶àÊýÃèÊöSQL Server 2005ÐÂÌØÐÔµÄÎÄÕ¶¼¹Ø×¢ÓÚ»ª¶ø²»ÊµµÄÌØÐÔ£¬ÈçSQLCLR»òXMLÊý¾ÝÀàÐÍ£¬¶ø¶ÔÐí¶àºÜºÃµÄÀϵÄT-SQLÓïÑԵĸĽøûÓеõ½Ó¦ÓеĹØ×¢¡£ÎÒÔø¾­´ÓÐí¶àDBA¿ÚÖÐÌýµ½ÁîËûÃǸüÐ˷ܵÄÊÇ¿´µ½T-SQLÓïÑԵĸĽø,¶ø²»ÊÇÄÇЩгöÏֺͷ¢²¼µÄ¹¦ÄÜ¡£¶ÔÓÚSQLÓïÑÔµÄÒ»¸öºÜÓÐÓõÄʵ¼Ê¸Ä½øÊÇOUTPUT×Ӿ䣬ËüÔÊÐí²éѯһ¸öÊý¾ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ