Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SQL_Module.cs 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System.Data.SqlClient;
  5. using System.Data;
  6. public class SQL_Module : MonoBehaviour
  7. {
  8. public static SqlConnection conn;
  9. public static SqlCommand cmd;
  10. public static SqlDataReader dr;
  11. public static SqlDataAdapter da;
  12. public static string ConString;
  13. public static string ConString1;
  14. public static string ConString2;
  15. public static string SQL1;
  16. public static bool T_SQL;
  17. public static void TestSQL(string TestConString){
  18. using (SqlConnection connection = new SqlConnection(TestConString))
  19. {
  20. try{
  21. connection.Open();
  22. Debug.Log("SQL Connection Successful");
  23. T_SQL=true;
  24. }
  25. catch (SqlException e){
  26. Debug.LogError("SQL Connection Error: " + e.Message);
  27. T_SQL=false;
  28. }
  29. finally{
  30. connection.Close();
  31. }
  32. }
  33. }
  34. public static void ConnOpen_SQL(){
  35. try{
  36. conn.Close();
  37. if (conn.State == ConnectionState.Closed){
  38. conn = new SqlConnection(ConString);
  39. conn.Open();
  40. }
  41. }catch{
  42. conn = new SqlConnection(ConString);
  43. conn.Open();
  44. }
  45. }
  46. public static void ConnOpen_SQL圖()
  47. {
  48. try
  49. {
  50. conn.Close();
  51. if (conn.State == ConnectionState.Closed)
  52. {
  53. conn = new SqlConnection(ConString1);
  54. conn.Open();
  55. }
  56. }
  57. catch
  58. {
  59. conn = new SqlConnection(ConString1);
  60. conn.Open();
  61. }
  62. }
  63. public static void ConnOpen_SQL音()
  64. {
  65. try
  66. {
  67. conn.Close();
  68. if (conn.State == ConnectionState.Closed)
  69. {
  70. conn = new SqlConnection(ConString2);
  71. conn.Open();
  72. }
  73. }
  74. catch
  75. {
  76. conn = new SqlConnection(ConString2);
  77. conn.Open();
  78. }
  79. }
  80. public static void CmdSet_For_DGV(string conString)
  81. {
  82. try{
  83. da = new SqlDataAdapter(SQL1,conString);
  84. }catch{
  85. }
  86. }
  87. public static void CmdSet_For_dr(){
  88. try{
  89. cmd = conn.CreateCommand();
  90. cmd.CommandText = SQL1;
  91. cmd.Connection = conn;
  92. dr = cmd.ExecuteReader();
  93. }catch{
  94. }
  95. }
  96. public static void CmdSet_For_pic(string 流水, byte[] 檔案, string 單號)
  97. {
  98. try
  99. {
  100. cmd = conn.CreateCommand();
  101. cmd.CommandText = SQL1;
  102. cmd.Connection = conn;
  103. cmd.Parameters.AddWithValue("@流水號", 流水);
  104. cmd.Parameters.AddWithValue("@binary_file", 檔案);
  105. cmd.Parameters.AddWithValue("@單號", 單號);
  106. dr = cmd.ExecuteReader();
  107. }
  108. catch
  109. {
  110. }
  111. }
  112. public static void CmdSet_For_post(string 內容)
  113. {
  114. try
  115. {
  116. cmd = conn.CreateCommand();
  117. cmd.CommandText = SQL1;
  118. cmd.Connection = conn;
  119. cmd.Parameters.AddWithValue("@內容", 內容);
  120. dr = cmd.ExecuteReader();
  121. }
  122. catch
  123. {
  124. }
  125. }
  126. }