CQ变量在SQLCommand中 [英] C# Variable in a SQLCommand

查看:65
本文介绍了CQ变量在SQLCommand中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是
如何在SqlCommand中传递变量?

Hi guys,
how can I pass a variable inside a SqlCommand?

     SqlCommand的命令2 =新的SqlCommand(QUOT; Exec的PROVA" + '" via.text"',连接2);

        &NBSP ;       connection2.Open();

     SqlCommand command2 = new SqlCommand("Exec prova "+'"via.text"', connection2);
                connection2.Open();

它给了我错误。该变量是命令中的via.text,它触发一个程序

非常感谢

it gives me error. The variable is via.text inside the command which trigger a procedure
Many Thanks

推荐答案

你需要使用SqlCommand中提供的Parameters集合将参数传递给Stroed过程,更好的方法是指定命令是执行存储过程而不是普通的sql查询,如下所示:

You will need to use the Parameters collection provided in the SqlCommand to pass the parameter to your Stroed procedure, and better way is to specify that the command is to execute a stored procedure not a plain sql query which would be something like:

SqlCommand command2 = new SqlCommand("prova", sqlCon); scCommand.CommandType = CommandType.StoredProcedure; scCommand.Parameters.Add(new SqlParameter("@SomeParameter",via.Text));


这篇关于CQ变量在SQLCommand中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆