1 --SQL自定義函數:
2
3 CREATE FUNCTION [GetProjectID] (@headStr nvarchar(10),@date datetime)
4 )
5
6 RETURNS NVARCHAR(200)
7
8 AS
9
10 BEGIN
11
12 --不能在自定義函數中用INSERT INTO
13
14 --insert into emos_cust(cust_name,dates)values(
15
16 --@headStr,@date
17
18 --)
19
20 return TEST BY HANSHU
21 END
代碼
1 /// <summary>
2 /// 獲取項目文件編號
[email protected] 塗聚文
3 /// </summary>
4 private void FileNo()
5 {
6
7 SqlConnection conn = new SqlConnection(connectionString);
8 string strSql = "GetProjectID"; //自定SQL函數
9 SqlCommand cmd = new SqlCommand(strSql, conn);
10 cmd.CommandType = CommandType.StoredProcedure;
11 cmd.Parameters.Add("@headStr", SqlDbType.NVarChar).Value = "ZQ3"; //輸入