機試
public class DBHelpSQL
{
public static string constr = @"server = XIAOQIANG-PC ;database = test2017;integrated security = true";
public static SqlConnection conn = null;
public static void tableChange(string sql,SqlParameter [] para = null)
{
SqlCommand cmd = new SqlCommand(sql, conn);
if(para != null)
{
cmd.Parameters.AddRange(para);
}
try
{
if(cmd.ExecuteNonQuery() > 0)
{
MessageBox.Show("執行成功");
}else
{
MessageBox.Show("請檢查數據庫中是否存在該數據");
}
}catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public static DataTable tableSelect(string sql,SqlParameter [] para = null)
{
SqlCommand cmd = new SqlCommand(sql, conn);
if (para != null)
{
cmd.Parameters.AddRange(para);
}
try
{
DataTable dt = new DataTable();
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ad.Fill(dt);
return dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
}
readme.txt
附加數據庫文件test2017.mdf
SQL文件夾下爲所有的sql語句操作
更改DBHelpSQL.cs中的連接字符串使之適應自己的電腦
info.doc爲數據庫設計文件
SOURCE下的backinfo.bak爲數據庫的備份文件
連接字符串 = @“server = <你的計算機名> ;database = test2017;integrated security = true”;
info.doc
基本信息:
計算機全名:XIAOQIANG-PC
數據庫名稱:test2017
Windows連接方式
連接字符串: @“server = XIAOQIANG-PC ;database = test2017;integrated security = true”
數據庫創建: