C#代碼:
public static DataTable SQL1(string SerialNumber, string type){
DataTable DT = new DataTable();
string conString = "Data Source=; Initial Catalog=;User ID=;Password=";//連接資料庫的字符
string sql = "Data";//要呼叫的存盤程序名
try
{
SqlConnection conStr = new SqlConnection(conString);//SQL資料庫連接物件,以資料庫鏈接字串為引數
SqlCommand comStr = new SqlCommand(sql, conStr);//SQL陳述句執行物件,第一個引數是要執行的陳述句,第二個是資料庫連接物件
comStr.CommandType = CommandType.StoredProcedure;//設定執行型別為存盤程序
//依次設定存盤程序的引數
comStr.Parameters.Add("@SerialNumber", SqlDbType.Text).Value = https://www.cnblogs.com/my2020/p/SerialNumber;
comStr.Parameters.Add("@type", SqlDbType.Text).Value = https://www.cnblogs.com/my2020/p/type;
conStr.Open();//打開資料庫連接
SqlDataAdapter SqlDataAdapter1 = new SqlDataAdapter(comStr);
SqlDataAdapter1.Fill(DT);
conStr.Close();//關閉連接
}
catch (Exception ex)
{
MessageBox.Show("操作不成功");
}
return DT;
}
資料庫中代碼:
ALTER procedure Data @SerialNumber VarChar (50), @type VarChar (10) as
BEGIN SELECT b1.LotNumber FROM m_HL100GEEPROM_T b1 WHERE SerialNumber=@SerialNumber
NED GO
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/61579.html
標籤:C#
上一篇:DataTable轉為TXT檔案
