【发布时间】:2017-02-22 07:51:19
【问题描述】:
在 sql 中,我通常使用
执行我的过程exec dbo.usp_FCS 'TIMV','serial'
我在 c# 中尝试了一些相同的东西,但似乎我弄错了
using (SqlConnection connection = new SqlConnection("Data Source=;Initial Catalog=;User ID=;Password="))
{
using (SqlCommand cmd = new SqlCommand("usp_FCS_GetUnitInfo_Takaya" + "'" + MachineName + " ','serial' " , connection))
{
try
{
connection.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
}
catch (SqlException ex)
{
label6.Visible = true;
label6.Text = string.Format("Failed to Access Database!\r\n\r\nError: {0}", ex.Message);
return;
}
}
}
我的问题是,如何使用 c# 为我的存储过程提供这两个输入“TIMV”和“串行”?
编辑:
我尝试过这样的事情:
using (SqlCommand cmd = new SqlCommand("usp_FCS_GetUnitInfo_Takaya" , connection))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@p1", SqlDbType.VarChar).Value = MachineName;
cmd.Parameters.Add("@p2", SqlDbType.VarChar).Value = "serial";
try
{ my code...
还是不行
【问题讨论】:
标签: c# sql-server tsql stored-procedures