使用SQL Conn的SQL连接

时间:2015-03-23 18:51:24

标签: c# sql

嗨,请问连接字符串有问题。试图在C#中调用存储过程...这里是我的代码

            SqlConnection conn = new SqlConnection("Hunt_Lisa");
            SqlCommand command = new SqlCommand("blkFinance_noheader", conn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@Path", fn));
            command.ExecuteNonQuery();

我提前感谢你的帮助......

1 个答案:

答案 0 :(得分:0)

这是我修改后的脚本版本...只想分享

using (SqlCommand cmd = new SqlCommand())
            {

                cmd.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Hunt_Lisa"].ConnectionString);
                cmd.CommandText = "blkFinance_noheader";
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@Path", SqlDbType.Text).Value = fn;
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();

            }