1 --SQL自定義函數(shù): 代碼
1 /// <summary> 2 /// 獲取項(xiàng)目文件編號(hào) [email protected] 涂聚文 3 /// </summary> 4 private void FileNo() 5 { 6 7 SqlConnection conn = new SqlConnection(connectionString); 8 string strSql = "GetProjectID"; //自定SQL函數(shù) 9 SqlCommand cmd = new SqlCommand(strSql, conn); 10 cmd.CommandType = CommandType.StoredProcedure; 11 cmd.Parameters.Add("@headStr", SqlDbType.NVarChar).Value = "ZQ3"; //輸入?yún)?shù) 12 cmd.Parameters.Add("@date", SqlDbType.DateTime).Value = System.DateTime.Now.ToShortDateString(); //輸入?yún)?shù) 13 cmd.Parameters.Add("@returnString", SqlDbType.NVarChar); 14 cmd.Parameters["@returnString"].Direction = ParameterDirection.ReturnValue; //返回參數(shù) 15 try 16 { 17 conn.Open(); 18 object o= cmd.ExecuteScalar(); 19 20 this.txtAFileNO.Text = cmd.Parameters["@returnString"].Value.ToString(); 21 22 //Response.Write(""); 23 24 } 25 catch (Exception ex) 26 { 27 28 this.txtAFileNO.Text = ex.Message; 29 30 } 31 finally 32 { 33 34 if (!(conn.State == ConnectionState.Closed)) 35 { 36 37 conn.Close(); 38 39 40 } 41 42 } 43 44 45 } |
|