想用winform写客户端,数据库用access,数据连接要放到什么地方,winform如何调用??谢谢!!
解决方案 »
- 研究了很久还是发现不了问题.哪位大虾能解决的?
- 如何在TextBox 输入城市编号时光标移开 Label上就显示城市名
- dataGridView 绑定 List<string>的问题
- UDP累加和校验问题?
- 我写了SOCKET有服务端和客户端,服务端没问题,但是客户端只有第一次发送的信息能收到,以后再发就收不到,如果把客户端改成每次发送重新建立SOCKET,发完后销毁就没问题,请问为什么?
- 请帮我写个正则表达式,请给予帮助。谢谢!
- 可以得到调用一个方法的对象名吗?可以得到调用此方的的对象的引用吗?一个对象可以知道是哪个对象创建的自己吗?
- 数据库中的数据进行加减运算 满意就结贴
- 一个函数如何访问另一个函数的局部变量??????
- 一对多表单中新增按钮的代码怎么写,应该注意什么?(100大洋)
- 水平稍微高一点的进来帮我看一下问题
- 请问关于网站(该网站主要是公司的简介/业务介绍/一个论坛)的报价,谢谢!
using System.Data;
using System.Data.OleDb;
using System.Xml;
namespace ACS
{
/// <summary>
/// ACES 的摘要描述。
/// 對數據進行基本的操作
/// </summary>
public class ACES
{
#region ACES 構造函數
public ACES()
{
}
#endregion #region 自定義變量
//Link DataBase String
private string sConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =ExTend.mdb ";
#endregion #region Return a OleDbConnection
/// <summary>
/// 返回一個數連接
/// </summary>
/// <returns>返回連接cn</returns>
private OleDbConnection Acs_cn()
{
OleDbConnection cn = new OleDbConnection(sConString);
if(cn.State == ConnectionState.Closed)
{
cn.Open();
}
return cn;
}
#endregion #region 查詢數據庫,返回查詢結果oDs
/// <summary>
/// 返回查詢結果
/// </summary>
/// <param name="sCmdString">查詢SQL字串</param>
/// <returns></returns>
public DataSet Retrieval(string sCmdString)
{
//建立連接
OleDbConnection cn = Acs_cn();
//建立Dataset對像
DataSet oDs = new DataSet();
try
{
//建立Adapter對像
OleDbDataAdapter myAdapter = new OleDbDataAdapter(sCmdString,cn);
myAdapter.Fill(oDs,"Result");
}
catch(Exception e)
{
throw e;
}
finally
{
cn.Close();
}
return oDs; }
#endregion #region 與數據庫進行交易
/// <summary>
/// 與數據庫進行交易 Succeed Return '1' Fail Return '-1'
/// </summary>
/// <param name="sCmdString">Operation SQL</param>
/// <returns></returns>
public int Translation(string sCmdString)
{
//定義操作變量,操作成功返回值為'1'
int nResult = -1;
//建立數據庫連接
OleDbConnection cn = Acs_cn();
//建立oledbcommand實例對像
OleDbCommand myCommand = new OleDbCommand(sCmdString,cn);
try
{
//執行操作
myCommand.ExecuteNonQuery();
nResult = 1;
}
catch(Exception e)
{
throw e;
}
finally
{
//關閉連接
cn.Close();
}
return nResult; }
#endregion } /// <summary>
/// 對SQL語句中用的參數進行格式化
/// </summary>
public class FormatSql
{
#region 構造函數
public FormatSql()
{
}
#endregion #region Format SQL string
public string SQLQ(string sText)
{
sText = "'"+sText+"'";
return sText;
} public string SQLQ(int n)
{
return n.ToString();
} public string SQLQ(double n)
{
return n.ToString();
} public string SQLQC(string sText)
{
sText = "'"+sText+"',";
return sText;
} public string SQLQC(int nText)
{
string sText = nText.ToString()+",";
return sText;
} public string SQLQC(double nText)
{
string sText = nText.ToString()+",";
return sText;
}
#endregion
}
}
using System;
using System.Data;
using ACS;namespace BarCode
{
/// <summary>
/// Translation 的摘要描述。
/// </summary>
public class Translation
{
#region 構造函數
public Translation()
{
}
#endregion #region 基本變量 private string sql = "";
private int nResult = -1;
private ACS.ACES cmnExec = new ACS.ACES();
private ACS.FormatSql cmnFormat = new FormatSql();
private DataSet oDs = new DataSet();
private DataSet oDs1 = new DataSet();
private int nWip_Id = -1;
public string sFactory_no = "";
public string sWip_No = "";
public string sPart_No = "";
public string sBox_No_Start = "";
public string sBox_Count = "";
public string sEcn_Ver = "";
public string sBios_Ver = "";
public int nModel = -1;
public string sLanguage = ""; #endregion #region 工單
public int Wip()
{
//判斷數據庫中是否存在此筆記錄,不存在則插入,存在則找出
//其對應的WIP_ID
sql = " SELECT * FROM WIP_INFO WHERE WIP_NO="+cmnFormat.SQLQ(sWip_No);
oDs = cmnExec.Retrieval(sql);
if(oDs.Tables[0].Rows.Count>0)
{
nWip_Id = int.Parse(oDs.Tables[0].Rows[0]["WIP_ID"].ToString().Trim());
nResult = nWip_Id;
}
else
{
sql = " INSERT INTO WIP_INFO";
sql += "(FACTORY_NO,WIP_NO,PART_NO,ECN_VER,BIOS_VER,BOX_INCEPT";
sql += ",BOX_SOURCE, CREATE_USER,CREATE_DATE,UPDATE_DATE)";
sql += "VALUES("+cmnFormat.SQLQC(sFactory_no)+cmnFormat.SQLQC(sWip_No)+cmnFormat.SQLQC(sPart_No);
sql += cmnFormat.SQLQC(sEcn_Ver)+cmnFormat.SQLQC(sBios_Ver);
sql += cmnFormat.SQLQC(sBox_No_Start)+cmnFormat.SQLQC(sBox_Count)+cmnFormat.SQLQC("ADMINISTRATOR");
sql += "Now(),Now())"; nResult = cmnExec.Translation(sql);
//插入成功後找出其對應的WIP_ID
if(nResult > 0)
{ sql = " SELECT * FROM WIP_INFO WHERE WIP_NO="+cmnFormat.SQLQ(sWip_No);
oDs = cmnExec.Retrieval(sql);
nWip_Id = int.Parse(oDs.Tables[0].Rows[0]["WIP_ID"].ToString().Trim());
nResult = nWip_Id;
}
}
return nWip_Id;
}
#endregion
}
}
using System;
using System.Data;
using ACS;namespace BarCode
{
/// <summary>
/// Translation 的摘要描述。
/// </summary>
public class Translation
{
#region 構造函數
public Translation()
{
}
#endregion #region 基本變量 private string sql = "";
private int nResult = -1;
private ACS.ACES cmnExec = new ACS.ACES();
private ACS.FormatSql cmnFormat = new FormatSql();
private DataSet oDs = new DataSet();
private DataSet oDs1 = new DataSet();
private int nWip_Id = -1;
public string sFactory_no = "";
public string sWip_No = "";
public string sPart_No = "";
public string sBox_No_Start = "";
public string sBox_Count = "";
public string sEcn_Ver = "";
public string sBios_Ver = "";
public int nModel = -1;
public string sLanguage = ""; #endregion #region 工單
public int Wip()
{
//判斷數據庫中是否存在此筆記錄,不存在則插入,存在則找出
//其對應的WIP_ID
sql = " SELECT * FROM WIP_INFO WHERE WIP_NO="+cmnFormat.SQLQ(sWip_No);
oDs = cmnExec.Retrieval(sql);
if(oDs.Tables[0].Rows.Count>0)
{
nWip_Id = int.Parse(oDs.Tables[0].Rows[0]["WIP_ID"].ToString().Trim());
nResult = nWip_Id;
}
else
{
sql = " INSERT INTO WIP_INFO";
sql += "(FACTORY_NO,WIP_NO,PART_NO,ECN_VER,BIOS_VER,BOX_INCEPT";
sql += ",BOX_SOURCE, CREATE_USER,CREATE_DATE,UPDATE_DATE)";
sql += "VALUES("+cmnFormat.SQLQC(sFactory_no)+cmnFormat.SQLQC(sWip_No)+cmnFormat.SQLQC(sPart_No);
sql += cmnFormat.SQLQC(sEcn_Ver)+cmnFormat.SQLQC(sBios_Ver);
sql += cmnFormat.SQLQC(sBox_No_Start)+cmnFormat.SQLQC(sBox_Count)+cmnFormat.SQLQC("ADMINISTRATOR");
sql += "Now(),Now())"; nResult = cmnExec.Translation(sql);
//插入成功後找出其對應的WIP_ID
if(nResult > 0)
{ sql = " SELECT * FROM WIP_INFO WHERE WIP_NO="+cmnFormat.SQLQ(sWip_No);
oDs = cmnExec.Retrieval(sql);
nWip_Id = int.Parse(oDs.Tables[0].Rows[0]["WIP_ID"].ToString().Trim());
nResult = nWip_Id;
}
}
return nWip_Id;
}
#endregion
}
}