如何在ado.net中调用存储过程 [英] How To call Store procedure in ado.net
本文介绍了如何在ado.net中调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生,
我想在ado.net中调用存储过程,然后将多个文本框中的值sho告诉我解决方案
sir,
I want to call store procedure in ado.net and sho the value in multiple text box plz tell me the solution
推荐答案
^ ]基础教程应该可以帮助您入门.
This[^] basic tutorial should help you get started.
我认为此 [ ^ ]将为您提供帮助.
更多 ^ ]
I think this[^] will help you.
More here[^]
您可以尝试这个
公共静态字符串ConnString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings [& TestTestString& quot;].ToString();
公共静态SqlConnection Conn = new SqlConnection(ConnString);
公共数据表ExecuteNonQuery(字符串SpName,List< SqlParameter>参数,bool isOutput)
{
SqlDataAdapter da =新的SqlDataAdapter();
DataTable dt = new DataTable();
试试
{
da.SelectCommand =新的SqlCommand();
da.SelectCommand.CommandText = SpName;
da.SelectCommand.CommandTimeout = 1000;
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Connection = Conn;
da.SelectCommand.Parameters.AddRange(para.ToArray());
Conn.Open();
da.Fill(dt);
}
catch(ex ex例外)
{
如果(Conn.State == ConnectionState.Open)
{
Conn.Close();
}
投掷;
}
终于
{
如果(Conn.State == ConnectionState.Open)
{
Conn.Close();
}
}
return dt;
}
此函数将返回数据表.....
You can try this
public static string ConnString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["TestConnectionString"].ToString();
public static SqlConnection Conn = new SqlConnection(ConnString);
public DataTable ExecuteNonQuery(string SpName, List<SqlParameter> para, bool isOutput)
{
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
try
{
da.SelectCommand = new SqlCommand();
da.SelectCommand.CommandText = SpName;
da.SelectCommand.CommandTimeout = 1000;
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Connection = Conn;
da.SelectCommand.Parameters.AddRange(para.ToArray());
Conn.Open();
da.Fill(dt);
}
catch (Exception ex)
{
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
}
throw;
}
finally
{
if (Conn.State == ConnectionState.Open)
{
Conn.Close();
}
}
return dt;
}
This function will return datatable.....
这篇关于如何在ado.net中调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文