zoukankan      html  css  js  c++  java
  • 在C#中怎么调用带参数的存储过程啊??

    1)执行一个没有参数的存储过程的代码如下:
    SqlConnection conn=new SqlConnection(“connectionString”);
    SqlDataAdapter da = new SqlDataAdapter();
    da.selectCommand = new SqlCommand();
    da.selectCommand.Connection = conn;
    da.selectCommand.CommandText = "NameOfProcedure";
    da.selectCommand.CommandType = CommandType.StoredProcedure;
    (2)执行一个有参数的存储过程的代码如下
    SqlConnection conn=new SqlConnection(“connectionString”);
    SqlDataAdapter da = new SqlDataAdapter();
    da.selectCommand = new SqlCommand();
    da.selectCommand.Connection = conn;
    da.selectCommand.CommandText = "NameOfProcedure";
    da.selectCommand.CommandType = CommandType.StoredProcedure;
    param = new SqlParameter("@ParameterName", SqlDbType.DateTime);
    param.Direction = ParameterDirection.Input;
    param.Value = Convert.ToDateTime(inputdate);
    da.selectCommand.Parameters.Add(param);
    若需要添加输出参数:
    param = new SqlParameter("@ParameterName", SqlDbType.DateTime);
    param.Direction = ParameterDirection.Output;
    param.Value = Convert.ToDateTime(inputdate);
    da.selectCommand.Parameters.Add(param);
    若要获得参储过程的返回值:
    param = new SqlParameter("@ParameterName", SqlDbType.DateTime);
    param.Direction = ParameterDirection.ReturnValue;
    转载 请注明原文地址并标明转载:http://www.cnblogs.com/laopo 商业用途请与我联系:lcfhn168@163.com
  • 相关阅读:
    IOS
    WAN
    在不同网段使用 VLAN 通信
    数据链路层
    GRE 协议
    路由协议 (1)
    隔离广播域的 VLAN 来了
    数据包的通信过程
    Webpack 原理浅析
    蒲公英 · JELLY技术周刊 Vol.16 谷歌首个线上 Web 开发者大会
  • 原文地址:https://www.cnblogs.com/laopo/p/4147053.html
Copyright © 2011-2022 走看看