csharp(C#) 调用SQL自定义函数返回值
2010-03-19 15:38
357 查看
代码 1 /// <summary>
2 /// 获取项目文件编号 geovindu@163.com 涂聚文
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);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@headStr", SqlDbType.NVarChar).Value = "ZQ3"; //輸入參數
cmd.Parameters.Add("@date", SqlDbType.DateTime).Value = System.DateTime.Now.ToShortDateString(); //輸入參數
cmd.Parameters.Add("@returnString", SqlDbType.NVarChar);
cmd.Parameters["@returnString"].Direction = ParameterDirection.ReturnValue; //返回參數
try
{
conn.Open();
object o= cmd.ExecuteScalar();
this.txtAFileNO.Text = cmd.Parameters["@returnString"].Value.ToString();
//Response.Write("");
}
catch (Exception ex)
{
this.txtAFileNO.Text = ex.Message;
}
finally
{
if (!(conn.State == ConnectionState.Closed))
{
conn.Close();
}
}
}
2 /// 获取项目文件编号 geovindu@163.com 涂聚文
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);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@headStr", SqlDbType.NVarChar).Value = "ZQ3"; //輸入參數
cmd.Parameters.Add("@date", SqlDbType.DateTime).Value = System.DateTime.Now.ToShortDateString(); //輸入參數
cmd.Parameters.Add("@returnString", SqlDbType.NVarChar);
cmd.Parameters["@returnString"].Direction = ParameterDirection.ReturnValue; //返回參數
try
{
conn.Open();
object o= cmd.ExecuteScalar();
this.txtAFileNO.Text = cmd.Parameters["@returnString"].Value.ToString();
//Response.Write("");
}
catch (Exception ex)
{
this.txtAFileNO.Text = ex.Message;
}
finally
{
if (!(conn.State == ConnectionState.Closed))
{
conn.Close();
}
}
}
相关文章推荐
- sql自定义函数及C#中调用
- Sql建立自定义函数(函数和调用实例)(转载)
- T-SQL 在SQLServer中调用Dll(c#函数)
- SQL 2000自定义函数调用GETDATE()报错
- PHP入门教程之自定义函数用法详解(创建,调用,变量,参数,返回值等)
- sql 调用自定义函数方法
- c#带参数和返回值的函数 开启线程调用的方法
- sql调用自定义函数
- SQL调用正则表达式自定义函数(转载:CSDN)
- SQL 中自定义的函数怎样调用?
- 视图或自定义函数调用存储过程结果集办法(可执行动态SQL)
- C#调用含有数组类形参和返回值的matlab函数实例
- 视图或自定义函数调用存储过程结果集办法(可执行动态SQL)
- 从 SQL 进行操作系统调用,DB2自定义函数的使用
- SQL 2000自定义函数调用GETDATE()报错
- PHP入门教程之自定义函数用法详解(创建,调用,变量,参数,返回值等)
- python自定义函数返回值调用
- Sql建立自定义函数(函数和调用实例)
- .net 调用 sql server 自定义函数,并输出返回值
- 【C#】 24. HybridLocalSearchSolver + 自定义函数调用 + AddConstraint (constraint===1)