【发布时间】:2018-10-24 19:00:20
【问题描述】:
我有两种方法。当我调用方法 glass 时,我需要在查询中插入值。如何在查询中插入方法的值?
我正在使用 MVC、C# 和 SQL Server。
我试过的代码:在这个方法中调用一个方法 glas
RController re = new RController();
re.Glas(C_E);
string insert = "INSERT INTO dbo.MEP (R1) VALUES (@code)";
using (SqlCommand command = new SqlCommand(insert, con))
{
command.Parameters.AddWithValue("@code", "HERE METHOD GLAS");
con.Open();
int result = command.ExecuteNonQuery();
}
方法 GLAS 返回一个字符串。该字符串是我需要在查询中插入的。查询位于另一个控制器方法(Rcontroller)中。
public void GLAS(string C_E)
{
// more code
if (i > 0)
{
string glas1 = "OK";
}
else
{
string glas1 = "Fail";
}
}
【问题讨论】: