我可以使用Db类型将表类型参数从C#添加到存储过程 [英] Can I Add Table Type Parameter From C# To Stored Procedure Using Db Type
本文介绍了我可以使用Db类型将表类型参数从C#添加到存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用Sytem.Data.DbType枚举将C#中的表类型参数添加到存储过程吗?
could I add table type parameter from C# to stored procedure using Sytem.Data.DbType enums?
推荐答案
只需使用Parameters.AddWithValue [ ^ ] - 它我会为你排序:传递SQL Server 2008中存储过程的数据表 [ ^ ]
Just use Parameters.AddWithValue[^] - it'll sort it all out for you: Passing a datatable to a Stored Procedure in SQL Server 2008[^]
检查以下代码:
你还需要将变量存储在db中作为您正在使用的数据类型。
check the following code:
Also you need to store the variable in db as the datatype you are using.
string nm, pass;
nm = textBox1.Text;
pass = textBox2.Text;
int status = 0;
string constring = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=Main_Database.mdf;Integrated Security=True";
SqlConnection sn = new SqlConnection(constring);
SqlCommand sm = new SqlCommand("searchUser", sn);
sm.CommandType = CommandType.StoredProcedure;
sm.Parameters.AddWithValue("@nm", nm);
sm.Parameters.AddWithValue("@pass", pass);
sm.Parameters.Add("@returnVal", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
using (sn)
{
sn.Open();
sm.ExecuteNonQuery();
status = (int)sm.Parameters["@returnVal"].Value;
}
这篇关于我可以使用Db类型将表类型参数从C#添加到存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文