[英]How can I retrieve parameters from SQL query using C#
I need help in retrieving parameters in SQL query (not stored procedure) and their data types in C#.我需要在 SQL 查询(不是存储过程)中检索参数及其在 C# 中的数据类型方面的帮助。 Here is a sample query.
这是一个示例查询。
Declare @param1 int
Declare @param2 varchar(255)
Select *
from tablenanme
where col1 = @param1 and col2 = @param2
How can I also assign these values dynamically in C#如何在 C# 中动态分配这些值
I've tried but I can really figure it out我试过了,但我真的能弄明白
Don't declare local variables in the batch.不要在批处理中声明局部变量。 Instead, add parameters/values to the command object:
相反,将参数/值添加到命令对象:
var command = new SqlCommand("Select * from tablenanme where col1=@param1 and col2=@param2", connection);
command.Parameters.Add("@param1", SqlDbType.Int).Value = col1Value;
command.Parameters.Add("@param2", SqlDbType.VarChar, 255).Value = co2Value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.