C#、SQL 查詢+修改+刪除+更新工具
1.登陸原始碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using System.Threading;
namespace QueryingTool.V1._00
{
public partial class Flogin : Form
{
public Flogin()
{
this.StartPosition = FormStartPosition.CenterScreen;
InitializeComponent();
}
private void Flogin_Load(object sender, EventArgs e)
{
this.textBox1.Focus();//焦點
this.textBox1.SelectAll();//選中
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (Char)Keys.Enter)
{
if (textBox1.Text != "" && textBox1.Text != null)
textBox2.Focus();
else
{
textBox1.Focus();
textBox1.SelectAll();
}
}
}
private void button1_Enter(object sender, EventArgs e)
{
if (textBox1.Text == "" && textBox1.Text == null)
{
textBox1.Focus();
textBox1.SelectAll();
}
else if (textBox2.Text == "" && textBox2.Text== null)
{
textBox2.Focus();
textBox2.SelectAll();
}
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" && textBox1.Text == null)
{
textBox1.Focus();
textBox1.SelectAll();
}
else if (textBox2.Text == "" && textBox2.Text == null)
{
textBox2.Focus();
textBox2.SelectAll();
}
else
{
SqlServer_Use MyLoginQuerying = new SqlServer_Use("GPUSERVER", "E_LoginInfo", "sa", "adminsystem", "usp_QueryUser_Pwd_Info");
if ((MyLoginQuerying.Querying_Login_UserName_Pwd(textBox1.Text.Trim(), textBox2.Text.Trim())) == true)
{
this.Hide();//隱身登陸介面
if (textBox1.Text.ToUpper() == "ADMIN")
{
Boot By = new Boot();
By.StartPosition = FormStartPosition.CenterScreen;
By.Show();
}
else
{
Querying Qy = new Querying();
Qy.StartPosition = FormStartPosition.CenterScreen;
Qy.Show();
}
}
else
{
MessageBox.Show("輸入的帳戶或密碼資訊錯誤!!","系統提醒",MessageBoxButtons.OK,MessageBoxIcon.Error);
textBox2.Text = "";
textBox1.Text = "";
textBox1.Focus();
textBox1.SelectAll();
}
}
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
//if (textBox2.Text != "" && textBox2.Text != null)
// button1.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
System.Environment.Exit(1);
}
}
}
2.選項塊原始碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace QueryingTool.V1._00
{
public partial class Boot : Form
{
public Boot()
{
InitializeComponent();
}
private void Boot_FormClosing(object sender, FormClosingEventArgs e)
{
System.Environment.Exit(1);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
this.Hide();
Querying Mq = new Querying();
Mq.StartPosition = FormStartPosition.CenterScreen;//居中顯示
Mq.Show();
}
else if (comboBox1.SelectedIndex == 1)
{
this.Hide();
ReworkItems Rq = new ReworkItems();
Rq.StartPosition = FormStartPosition.CenterScreen;//居中顯示
Rq.Show();
}
}
}
}
3.查詢匯出模組原始碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using System.Threading;
using System.Diagnostics;
using System.Collections;
using System.Web;
namespace QueryingTool.V1._00
{
public partial class Querying : Form
{
public struct Config
{
public String Querying_ItemName;
public String Querying_DATABASE;
public String Querying_DATATABLE;
public List<String> KeyItemName;
}
List<Config> StoredConfigInfo = new List<Config>();
public String QDATABASE;
public String DATATABLE;
public Querying()
{
InitializeComponent();
}
private void Querying_FormClosing(object sender, FormClosingEventArgs e)
{
System.Environment.Exit(1);
}
private void Querying_Load(object sender, EventArgs e)
{
if (ConfigRead_Stored() == true)
{
}
else
{
MessageBox.Show("Query.Config配置檔案讀取出錯!!","系統提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
public void Errlog(String Err_Str)//生成Log記錄
{
FileStream fs = new FileStream("Err.log",FileMode.Create,FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(Err_Str);
sw.Close();
fs.Close();
}
public Boolean ConfigRead_Stored()
{
Boolean Flag = false;
try
{
FileStream fs = new FileStream("Query.Config",FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs,Encoding.Default);
String Temp = String.Empty;
while ((Temp = sr.ReadLine()) != null)
{
if (Temp[0] != '#')
{
String[] ArrayStr = Temp.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (ArrayStr.Length >= 4)
{
Config My_Cfg = new Config();
My_Cfg.Querying_ItemName = ArrayStr[0].Trim();//查詢專案名稱
My_Cfg.Querying_DATABASE = ArrayStr[1].Trim();//查詢資料庫
My_Cfg.Querying_DATATABLE = ArrayStr[2].Trim();//查詢資料表
List<String> KeyItemName = new List<String>();
for (int n = 3; n < ArrayStr.Length; n++)
KeyItemName.Add(ArrayStr[n].Trim());
My_Cfg.KeyItemName=KeyItemName;//新增選擇關鍵項
comboBox1.Items.Add(ArrayStr[0].Trim());
StoredConfigInfo.Add(My_Cfg);
}
}
}
Flag = true;
}
catch (Exception ex)
{
Flag = false;
this.Errlog(ex.ToString());
}
return Flag;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text != "" && comboBox1.Text != null)
{
foreach (Config cc in StoredConfigInfo)
{
if (cc.Querying_ItemName == comboBox1.Text.Trim())
{
this.QDATABASE = cc.Querying_DATABASE;
this.DATATABLE = cc.Querying_DATATABLE;
foreach (String ii in cc.KeyItemName)
comboBox2.Items.Add(ii);
comboBox1.Enabled = false;
comboBox2.Enabled = true;
comboBox2.Focus();
button3.Enabled = true;
}
}
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.Text != null && comboBox2.Text != "")
{
if (comboBox2.Text == "*")
{
comboBox2.Enabled = false;
button1.Enabled = true;
button1.Focus();
}
else
{
comboBox2.Enabled = false;
textBox1.Enabled = true;
textBox1.Focus();
}
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
textBox1.Enabled = false;
button1.Enabled = true;
button1.Focus();
}
}
private void button1_Click(object sender, EventArgs e)
{
String Stored_Procedure = String.Empty;
if (comboBox2.Text == "*")
Stored_Procedure = "SELECT * FROM " + this.DATATABLE;
else if (comboBox2.Text == "Date_Time")
Stored_Procedure = "SELECT * FROM " + this.DATATABLE + " WHERE Date_Time like " + @"'" + textBox1.Text.Trim() + @"%'";
else
Stored_Procedure = "SELECT * FROM " + this.DATATABLE + " WHERE " + comboBox2.Text.Trim() + "=" + @"'" + textBox1.Text.Trim() + @"'";
SqlServer_Use My_Querying = new SqlServer_Use("GPUSERVER",this.QDATABASE,"sa","adminsystem",Stored_Procedure);
if (My_Querying.DataBaseQuerying_SpecifyTheData(dataGridView1, label1) == false)
{
MessageBox.Show("資料查詢出錯!!", "系統提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
if (dataGridView1.Rows.Count > 1)
{
button1.Enabled = false;
button2.Enabled = true;
button3.Enabled = true;
}
}
}
private void button3_Click(object sender, EventArgs e)
{
Reset(1);
}
private void Reset(int Items)
{
if (Items == 1)
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
textBox1.Text = "";
textBox1.Enabled = false;
comboBox2.Items.Clear();
comboBox2.Text = "";
comboBox1.Text = "";
comboBox1.Enabled = true;
comboBox1.Focus();
dataGridView1.DataSource = null;//清空資料表
}
}
public static Boolean ExportExcel_DefineTheForm(string fileName, DataGridView myDGV)//按定義的表格匯出資料
{
Boolean Flag=false;
if (myDGV.Rows.Count > 0)//存在測試資料
{
String saveFileName = "";
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.DefaultExt = "xls";
saveDialog.Filter = "Excel檔案|*.xls";
saveDialog.FileName = fileName;
saveDialog.ShowDialog();
saveFileName = saveDialog.FileName;
if (saveFileName.IndexOf(":") < 0)
{
return true;
}
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
if (xlApp == null)
{
MessageBox.Show("無法建立Excel物件,可能您的系統未安裝Excel", "系統提醒", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks;
Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];//取得sheet1
//寫入標題
for (int i = 0; i < myDGV.ColumnCount; i++)
{
worksheet.Cells[1, i + 1] = myDGV.Columns[i].HeaderText;
}
//寫入數值
for (int r = 0; r < myDGV.Rows.Count; r++)
{
for (int i = 0; i < myDGV.ColumnCount; i++)
{
worksheet.Cells[r + 2, i + 1] = myDGV.Rows[r].Cells[i].Value;
}
System.Windows.Forms.Application.DoEvents();
}
worksheet.Columns.EntireColumn.AutoFit();//列寬自適應
if (saveFileName != "")
{
try
{
workbook.Saved = true;
workbook.SaveCopyAs(saveFileName);
Flag = true;
}
catch (Exception ex)
{
MessageBox.Show("匯出檔案時出錯,檔案可能正被開啟!\n" + ex.Message, "系統提醒", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
return false;
}
}
xlApp.Quit();
GC.Collect();//強行銷燬
MessageBox.Show("匯出檔案成功", "提示", MessageBoxButtons.OK);
}
else
{
MessageBox.Show("報表為空,無表格需要匯出", "提示", MessageBoxButtons.OK);
return true;
}
return Flag;
}
private void button2_Click(object sender, EventArgs e)
{
String FileName = DateTime.Now.ToString("yyyyMMddHHmmss");
if (ExportExcel_DefineTheForm(FileName, this.dataGridView1) == true)
{
button1.Enabled = false;
button3.Enabled = false;
comboBox1.Enabled = true;
}
}
}
}
3.刪除\更新\新增
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
namespace QueryingTool.V1._00
{
public partial class ReworkItems : Form
{
public struct Config
{
public String Item_Name;
public String RDATABASE;
public String RDATATABLE;
public List<String> KeyItemName;
}
List<Config> StoredConfigInfo = new List<Config>();
public String RDATABASE;
public String RDATATABLE;
public List<ComboBox> MyCb=new List<ComboBox>();
public List<TextBox> MyTb=new List<TextBox>();
public List<Button> MyBt=new List<Button>();
public ReworkItems()
{
InitializeComponent();
}
private void ReworkItems_FormClosing(object sender, FormClosingEventArgs e)
{
System.Environment.Exit(1);
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
InitControl(1);
if (ReadCfg("Rework.Config") == true)
{
comboBox1.Enabled = true;
}
else
{
label10.Text = "讀取Rework.Config配置出錯!!";
label10.ForeColor = Color.Red;
}
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
InitControl(1);
comboBox4.Enabled = true;
comboBox4.Items.Add("更新MAC字首資訊");
comboBox4.Items.Add("更新老化時間");
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked == true)
{
InitControl(1);
comboBox6.Items.Add("增加MAC字首資訊");
comboBox6.Items.Add("增加老化時間資料");
}
}
private void ReworkItems_Load(object sender, EventArgs e)
{
MyCb.Add(comboBox1);
MyCb.Add(comboBox2);
MyCb.Add(comboBox3);
MyCb.Add(comboBox4);
MyCb.Add(comboBox5);
MyCb.Add(comboBox6);
MyCb.Add(comboBox7);
MyCb.Add(comboBox8);
MyCb.Add(comboBox9);
MyTb.Add(textBox1);
MyTb.Add(textBox2);
MyTb.Add(textBox3);
MyTb.Add(textBox4);
MyBt.Add(button1);
MyBt.Add(button2);
MyBt.Add(button3);
}
public Boolean ReadCfg(String FileName)
{
Boolean Flag = false;
try
{
FileStream fs = new FileStream(FileName,FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs,Encoding.Default);
String Temp = String.Empty;
while ((Temp = sr.ReadLine()) != null)
{
if (Temp[0] != '#')
{
String[] Array_Str = Temp.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries);
Config MyC = new Config();
MyC.Item_Name = Array_Str[0].Trim();
MyC.RDATABASE = Array_Str[1].Trim();
MyC.RDATATABLE = Array_Str[2].Trim();
List<String> TemL = new List<string>();
for (int n = 3; n < Array_Str.Length; n++)
{
TemL.Add(Array_Str[n].Trim());
}
MyC.KeyItemName = TemL;
StoredConfigInfo.Add(MyC);
comboBox1.Items.Add(Array_Str[0].Trim());
}
}
Flag = true;
}
catch (Exception ex)
{
this.Errlog(ex.ToString());
Flag = false;
}
return Flag;
}
public void Errlog(String Err_Str)
{
FileStream fs = new FileStream("Err.log",FileMode.Create,FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(sw);
sw.Close();
fs.Close();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Clear();
comboBox2.Enabled = true;
comboBox2.Focus();
comboBox2.Text = "";
comboBox1.Enabled = false;
label10.Text = "";
foreach (Config ss in StoredConfigInfo)
{
if (comboBox1.Text == ss.Item_Name.Trim())
{
this.RDATABASE = ss.RDATABASE;
this.RDATATABLE = ss.RDATATABLE;
foreach (String ii in ss.KeyItemName)
comboBox2.Items.Add(ii);
}
}
}
public void InitControl(int Items)
{
int Item = 0;
if (radioButton1.Checked == true && Items == 1) Item = 1;
else if (radioButton2.Checked == true && Items == 1) Item = 4;
else if (radioButton3.Checked == true && Items == 1) Item = 6;
int ss = 1;
foreach (ComboBox cc in MyCb)
{
if (Item != ss)
{
cc.Items.Clear();
cc.Text = "";
cc.Enabled = false;
}
else
{
cc.Text = "";
cc.Enabled = true;
}
ss++;
}
foreach (TextBox tt in MyTb)
{
tt.Text = "";
tt.Enabled = false;
}
foreach (Button bb in MyBt)
bb.Enabled = false;
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Enabled = false;
textBox1.Text = "";
textBox1.Enabled = true;
textBox1.Focus();
label10.Text = "";
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
if (textBox1.Text != "" && textBox1.Text != null)
{
button1.Enabled = true;
textBox1.Enabled = false;
button1.Focus();
}
else
{
label10.Text = "刪除欄->錄入關鍵值項內容不能為空!!";
label10.ForeColor = Color.Red;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
String Stored_Procedure=String.Empty;
if (comboBox2.Text.Trim() == "Date_Time")
Stored_Procedure = "DELETE " + this.RDATATABLE + " WHERE " + comboBox2.Text.Trim() + " like " + @"'" + textBox1.Text.Trim() + @"%'";
else
Stored_Procedure = "DELETE " + this.RDATATABLE + " WHERE " + comboBox2.Text.Trim() + "=" + @"'" + textBox1.Text.Trim() + @"'";
SqlServer_Use My_Del = new SqlServer_Use("GPUSERVER",this.RDATABASE,"sa","adminsystem",Stored_Procedure);
if (My_Del.TestData_Operate()== true)
{
label10.ForeColor = Color.Green;
label10.Text = My_Del.ResString;
InitControl(1);
}
else
{
label10.ForeColor = Color.Red;
label10.Text = My_Del.ResString;
}
}
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
label10.Text = "";
comboBox3.Items.Clear();
if (comboBox4.Text.Trim() == "更新MAC字首資訊")
{
this.RDATABASE = "E_AgeTestData";
this.RDATATABLE = "Mac_Section";
comboBox3.Items.Add("TradeName");
comboBox3.Items.Add("Address_Section");
}
else if (comboBox4.Text.Trim() == "更新老化時間")
{
this.RDATABASE = "E_AgeTestData";
this.RDATATABLE = "Agin_SetTime";
comboBox3.Items.Add("Trade_Name");
comboBox3.Items.Add("AginTime");
}
comboBox4.Enabled = false;
comboBox3.Enabled = true;
comboBox3.Focus();
}
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
comboBox8.Items.Clear();
if (textBox2.Text != null && textBox2.Text != "")
{
String Stored_Procedure=String.Empty;
Stored_Procedure="SELECT "+comboBox7.Text.Trim()+" FROM "+this.RDATATABLE;
SqlServer_Use MyRKy = new SqlServer_Use("GPUSERVER", this.RDATABASE, "sa", "adminsystem", Stored_Procedure);
if (MyRKy.ReadKeyValues() == true)
{
foreach (String kk in MyRKy.KeyValues)
comboBox8.Items.Add(kk.Trim());
textBox2.Enabled = false;
comboBox8.Enabled = true;
comboBox8.Focus();
}
else
{
label10.ForeColor = Color.Red;
label10.Text = MyRKy.ResString;
}
}
else
{
label10.ForeColor = Color.Red;
label10.Text = "更新欄->錄入設定值內容能不為空!!";
}
}
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
textBox2.Enabled = true;
textBox2.Text = "";
textBox2.Focus();
comboBox3.Enabled = false;
if (comboBox3.Text.Trim() == "TradeName")
{
comboBox7.Text = "Address_Section";
}
else if (comboBox3.Text.Trim() == "Address_Section")
{
comboBox7.Text = "TradeName";
}
else if (comboBox3.Text.Trim() == "Trade_Name")
{
comboBox7.Text = "AginTime";
}
else if (comboBox3.Text.Trim() == "AginTime")
{
comboBox7.Text = "Trade_Name";
}
}
private void button2_Click(object sender, EventArgs e)
{
String Stored_Procedure = String.Empty;
if (comboBox3.Text == "AginTime")
{
Stored_Procedure = "UPDATE " + this.RDATATABLE + " SET " + comboBox3.Text.Trim() + "=" + textBox2.Text.Trim() + " where " + comboBox7.Text.Trim() + "=" + @"'" + comboBox8.Text.Trim() + @"'";
}
else if (comboBox7.Text == "AginTime")
{
Stored_Procedure = "UPDATE " + this.RDATATABLE + " SET " + comboBox3.Text.Trim() + "=" + @"'" + textBox2.Text.Trim() + @"'" + " where " + comboBox7.Text.Trim() + "=" + comboBox8.Text.Trim();
}
else
{
Stored_Procedure = "UPDATE " + this.RDATATABLE + " SET " + comboBox3.Text.Trim() + "=" + @"'" + textBox2.Text.Trim() + @"'" + " where " + comboBox7.Text.Trim() + "=" + @"'" + comboBox8.Text.Trim() + @"'";
}
SqlServer_Use MyUp = new SqlServer_Use("GPUSERVER", this.RDATABASE, "sa", "adminsystem", Stored_Procedure);
if (MyUp.TestData_Operate() == true)
{
label10.ForeColor = Color.Green;
label10.Text = MyUp.ResString;
InitControl(1);
}
else
{
label10.ForeColor = Color.Red;
label10.Text = MyUp.ResString;
}
}
private void comboBox8_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox8.Enabled = false;
button2.Enabled = true;
}
private void comboBox6_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox6.Enabled = false;
label10.Text = "";
if (comboBox6.Text.Trim() == "增加MAC字首資訊")
{
comboBox5.Text="TradeName";
comboBox9.Text="Address_Section";
this.RDATABASE = "E_AgeTestData";
this.RDATATABLE = "Mac_Section";
}
else if (comboBox6.Text.Trim() == "增加老化時間資料")
{
comboBox5.Text = "Trade_Name";
comboBox9.Text = "AginTime";
this.RDATABASE = "E_AgeTestData";
this.RDATATABLE = "Agin_SetTime";
}
textBox3.Text = "";
textBox3.Enabled = true;
textBox3.Focus();
}
private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
label10.Text = "";
if (textBox3.Text != "" && textBox3.Text != null)
{
textBox3.Enabled = false;
textBox4.Text = "";
textBox4.Enabled = true;
textBox4.Focus();
}
else
{
label10.ForeColor = Color.Red;
label10.Text = "新增欄->錄入鍵值_1內容能不為空!!";
}
}
}
private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
label10.Text = "";
if (textBox4.Text != "" && textBox4.Text != null)
{
button3.Enabled = true;
textBox4.Enabled = false;
button3.Focus();
}
else
{
label10.ForeColor = Color.Red;
label10.Text = "新增欄->錄入鍵值_2內容能不為空!!";
}
}
}
private void button3_Click(object sender, EventArgs e)
{
label10.Text = "";
String Stored_Procedure = String.Empty;
if (comboBox9.Text.Trim() == "AginTime")
{
Stored_Procedure="INSERT INTO "[email protected]" VALUES("[email protected]"'"+textBox3.Text.Trim()[email protected]"'"+","+textBox4.Text.Trim()[email protected]")";
}
else
{
Stored_Procedure = "INSERT INTO " + this.RDATATABLE + @" VALUES(" + @"'" + textBox3.Text.Trim() + @"'" + "," + @"'"+textBox4.Text.Trim() + @"'"[email protected]")";
}
SqlServer_Use MyIn = new SqlServer_Use("GPUSERVER", this.RDATABASE, "sa", "adminsystem", Stored_Procedure);
if (MyIn.TestData_Operate() == true)
{
label10.ForeColor = Color.Green;
label10.Text = MyIn.ResString;
InitControl(1);
}
else
{
label10.ForeColor = Color.Red;
label10.Text = MyIn.ResString;
}
}
}
}
4.共用資料庫連線模組:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Diagnostics;
using System.Collections;
using System.Web;
using System.Drawing;
namespace QueryingTool.V1._00
{
public class SqlServer_Use:Querying
{
private String SERVER;
private String DATABASE;
private String UID;
private String PWD;
private String Stored_Procedure;
public String ResString;
public List<String> KeyValues;
public SqlServer_Use(String SERVER, String DATABASE, String UID, String PWD, String Stored_Procedure)
{
this.SERVER = SERVER;
this.DATABASE = DATABASE;
this.UID = UID;
this.PWD = PWD;
this.Stored_Procedure = Stored_Procedure;
}
public Boolean ReadKeyValues()//讀取資料庫鍵值
{
Boolean Flag = false;
String Conn_Str = String.Empty;
Conn_Str = "server=" + this.SERVER + ";database=" + this.DATABASE + ";uid=" + this.UID + ";pwd=" + this.PWD;
SqlConnection conn = new Sq