日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#數(shù)據(jù)訪問層的相關(guān)知識

C#數(shù)據(jù)訪問層1.查詢數(shù)據(jù)庫中的數(shù)據(jù),返回一個datatable

站在用戶的角度思考問題,與客戶深入溝通,找到黃巖網(wǎng)站設(shè)計與黃巖網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名注冊、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋黃巖地區(qū)。

C#數(shù)據(jù)訪問層2.執(zhí)行一條SQL語句已重載

 
 
 
  1. using System;
  2. using System.Data;
  3. using NUnit.Framework;
  4. using CodeFilemanger.Project;
  5. using System.Data.SqlClient;
  6. using System.Configuration;
  7. namespace OperatorDB
  8. {
  9. /// 
  10. /// Class1 的摘要說明。
  11. /// 
  12. [NUnit.Framework.TestFixture]
  13. public class OperatorDB 
  14. private static string strCon = ConfigurationSettings.AppSettings["ConnectionString"] ; 
  15. private int ModuleId = 1;
  16. public static string ConnectionString 
  17. get 
  18. return strCon; 
  19. set 
  20. strCon = value; 
  21. #region "初始化" 
  22. [NUnit.Framework.TestFixtureSetUp]
  23. public void Register_Module()
  24. string ModuleName = "OperatorDB";
  25. string ModuleAuthor = "MYM";
  26. string ModuleDescribe = "數(shù)據(jù)訪問模塊";
  27. string CreateDatetime = "2003-5-30";
  28. ModuleId = Project.InsertModule( ModuleName, ModuleAuthor, ModuleDescribe, CreateDatetime) ; 
  29. }
  30. [Test]
  31. public void Register_Method_SelectData()
  32. {
  33. string MethodName = "SelectData";
  34. string MethodAuthor = "MYM";
  35. string MethodCreateDateTime = "2005-3-30";
  36. string MethodParaMeters ="ParaMeters(string SqlCommandText, System.Data.DataTable Dt, bool RowsClearr)";
  37. string MethodReturn = "bool";
  38. string MethodCall = "" ;
  39. string MethodDescribe = "查詢數(shù)據(jù)庫中的數(shù)據(jù),返回一個datatable";
  40. Project.InsertMethod(MethodName,MethodAuthor,MethodCreateDateTime,MethodParaMeters,MethodReturn,MethodCall,MethodDescribe,ModuleId); 
  41. }
  42. [Test]
  43. public void Register_Method_ExecuteSql()
  44. {
  45. string MethodName = "ExecuteSql";
  46. string MethodAuthor = "MYM";
  47. string MethodCreateDateTime = "2005-3-30";
  48. string MethodParaMeters ="ParaMeters(string SqlCommandText)";
  49. string MethodReturn = "int";
  50. string MethodCall = "" ;
  51. string MethodDescribe = "執(zhí)行一條SQL語句";
  52. Project.InsertMethod(MethodName,MethodAuthor,MethodCreateDateTime,MethodParaMeters,MethodReturn,MethodCall,MethodDescribe,ModuleId); 
  53. }
  54. [Test]
  55. public void Register_Method_SerialNumber()
  56. {
  57. string MethodName = "SerialNumber";
  58. string MethodAuthor = "MYM";
  59. string MethodCreateDateTime = "2005-3-30";
  60. string MethodParaMeters ="ParaMeters(int index, System.Data.DataTable dt)";
  61. string MethodReturn = "void";
  62. string MethodCall = "" ;
  63. string MethodDescribe = "給表的指定列添加序號";
  64. Project.InsertMethod(MethodName,MethodAuthor,MethodCreateDateTime,MethodParaMeters,MethodReturn,MethodCall,MethodDescribe,ModuleId); 
  65. }
  66. #endregion 
  67. public static bool SelectData(string SqlCommandText, System.Data.DataTable Dt, bool RowsClearr) 
  68. strCon = ConfigurationSettings.AppSettings["ConnectionString"]; 
  69. bool ret = true
  70. if (SqlCommandText != "") 
  71. if (RowsClearr) 
  72. if (Dt.Rows.Count > 0)
  73. {
  74. Dt.Rows.Clear(); 
  75. }
  76. SqlConnection cn = new SqlConnection(strCon); 
  77. SqlDataAdapter da = new SqlDataAdapter(SqlCommandText, cn); 
  78. try 
  79. cn.Open(); 
  80. da.Fill(Dt); 
  81. catch (System.Exception ex) 
  82. ExceptionHand exc = new ExceptionHand(ex); 
  83. exc.DisplayErrorMessager("OperatorDB","SelectData",SqlCommandText); 
  84. ret = false
  85. if (cn.State == ConnectionState.Open) 
  86. cn.Close(); 
  87. da.Dispose(); 
  88. else 
  89. ret = false
  90. return ret; 
  91. public static int ExecuteSql(string SqlCommandText) 
  92. int ID = 0; 
  93. strCon = ConfigurationSettings.AppSettings["ConnectionString"]; 
  94. if (SqlCommandText != "") 
  95. SqlConnection cn = new SqlConnection(strCon); 
  96. SqlCommand cm = new SqlCommand(SqlCommandText, cn); 
  97. try 
  98. cn.Open();
  99. ID = Convert.ToInt32(cm.ExecuteScalar());
  100. catch (System.Exception ex) 
  101. cn.Close();
  102. ExceptionHand exc = new ExceptionHand(ex); 
  103. exc.DisplayErrorMessager("OperatorDB","ExecuteSql",SqlCommandText); 
  104. ID = -1; 
  105. if (cn.State == ConnectionState.Open) 
  106. cn.Close(); 
  107. cm.Dispose(); 
  108. return ID; 
  109. public static int ExecuteSql(SqlCommand Cm) 
  110. int ID = 0; 
  111. strCon = ConfigurationSettings.AppSettings["ConnectionString"]; 
  112. SqlConnection cn = new SqlConnection(strCon); 
  113. try 
  114. cn.Open(); 
  115. Cm.Connection = cn;
  116. ID = Convert.ToInt32(Cm.ExecuteScalar()); 
  117. catch (System.Exception ex) 
  118. cn.Close();
  119. ExceptionHand exc = new ExceptionHand(ex); 
  120. exc.DisplayErrorMessager("OperatorDB","ExecuteSql",Cm.CommandText); 
  121. ID = -1; 
  122. if (cn.State == ConnectionState.Open) 
  123. cn.Close(); 
  124. Cm.Dispose(); 
  125. return ID; 
  126. public static void SerialNumber(int index, System.Data.DataTable dt) 
  127. for (int i = 0; i <= dt.Rows.Count - 1; i++) 
  128. dt.Rows[i][index] = i + 1; 
  129. public static void SetSqlCommandValues(SqlCommand Com,DataTable Dt,int Index,int StartIndex)
  130. {
  131. int i;
  132. for (i=StartIndex;i{
  133. Com.Parameters.Add("@" + Dt.Columns[i].ColumnName,Dt.Rows[Index][i]);
  134. }
  135. }
  136. }

C#數(shù)據(jù)訪問層的相關(guān)知識就介紹到這里。


分享標(biāo)題:C#數(shù)據(jù)訪問層的相關(guān)知識
文章網(wǎng)址:http://www.dlmjj.cn/article/dppgige.html