要寻找拯救,需要使用字节数组密码在此使用的方法后
那么我应该在sql server中使用哪种数据类型来保存字节数组?以及如何使用SqlCommand传递和检索字节数组?
这是以下代码健康吗?或者我不需要使用using关键字作为SqlDataAdapter将处理关闭连接?
public static DataSet Fetch(string sp, SqlParameter [] prm)
{
using (SqlConnection con = new SqlConnection(ConStr))
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = sp;
cmd.Parameters.AddRange(prm);
using (SqlDataAdapter dta = new SqlDataAdapter(cmd))
{
DataSet dst = new DataSet();
dta.Fill(dst);
return dst;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
@MarkGravell我在这里需要一个建议,我真的很想使用DataReader,但我一直在寻找使用该using关键字以确保关闭连接.在哪里DataReader我们不能使用它,因为如果我们想要返回DataReader某个方法,它将关闭连接.所以你认为以下技术DataReader和using关键字一样好:
public static SqlDataReader Fetch(string sp, SqlParameter [] prm)
{
SqlCommand cmd = new SqlConnection(ConStr).CreateCommand(); …Run Code Online (Sandbox Code Playgroud)