首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

根據預存程序名稱產生 ADO.NET 資料庫存取代碼(二):測試與輸出範例

     編輯:關於C語言

測試代碼

sqltoolforexcuteandadapter 'YourProcName',1 -- or 0

顯示結果:

SqlConnection conn = new SqlConnection("");
SqlCommand com = new SqlCommand("YourProcName", conn);
com.CommandType = CommandType.StoredProcedure;
SqlParameter[] Parameters = new SqlParameter[1];
Parameters[0] = new SqlParameter("@yourparam", SqlDbType.VarChar);
Parameters[0].Value = ?;
Parameters[0].Size = 6;
com.Parameters.AddRange(Parameters);
try
{
    da.Fill(ds);
}
catch (Exception ee)
{
    throw ee;
}
finally
{
    // do what you want to do or dispose resources.
}

這樣非常方便,且不用手寫大量參數,參數指定精確長度與型別,速度更快。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved