SQL.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using MySql.Data.MySqlClient;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Data.OleDb;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. namespace BaseLibDataProcess
  10. {
  11. public class SQLFunction
  12. {
  13. /// <summary>
  14. /// 获取指定表的指定字段的指定值的插入语句
  15. /// </summary>
  16. /// <param name="Table">表</param>
  17. /// <param name="arrField">字段</param>
  18. /// <param name="arrValue">值</param>
  19. /// <returns>字符串值</returns>
  20. public static string getInsertString(string Function, string Table, string[] arrField, string[] arrValue)
  21. {
  22. string strSQL = string.Empty;
  23. if (arrField.Length != arrValue.Length)
  24. {
  25. throw new OraDBBaseException("字段的个数和值的个数不一致");
  26. }
  27. string str1 = "", str2 = "";
  28. strSQL = Function + " into " + Table + "(";
  29. for (int i = 0; i < arrField.Length; i++)
  30. {
  31. str1 += string.Format("{0},", arrField[i]);
  32. str2 += string.Format("'{0}',", arrValue[i]);
  33. }
  34. strSQL += str1.Substring(0, str1.Length - 1) + ") values (";
  35. strSQL += str2.Substring(0, str2.Length - 1) + ")";
  36. return strSQL;
  37. }
  38. public enum SQLname
  39. {
  40. insert,
  41. update,
  42. delete
  43. }
  44. }
  45. }