请帮助这个 [英] PLEASE HELP REGARDING THIS
问题描述
我想在他的querry中使用一个变量。
我可以像使用它一样...
select * from students where name ='textbox.text'...... ????
如果没有那么请帮助如何使用在运行时可能包含值的变量时间,我们可以在querry中使用那个变量吗?
例如。当我在文本框中输入单词rahul时,我想运行一个
查询,例如Select * from customers WHERE name = textbox.Text
我不知道如何在查询中使用文本框名称,我认为这应该引导我找到名字的解决方案。
I want to use a variable in he querry.
can i use it like...
select * from students where name='textbox.text' ......????
if not then please help how to use a variable that may contain a value at run time and can we use that variable in the querry??
for instance. when i type the word "rahul" in the textbox i want to run a
query like " Select * from customers WHERE name = textbox.Text "
I do not know how to use the textbox name in the query, I think this should
lead me to the solution on finding names.
推荐答案
您可以传递命令参数 - SqlCommand.Parameters属性 [ ^ ]。命令参数用于将数据从输入字段传递到在后端执行的查询。
You can pass command parameters - SqlCommand.Parameters Property [^]. Command parameters are used to pass data from input fields into a query that executes on the back end.
尝试,
SqlCommand .CommandText =SELECT * FROM students WHERE name = @Name;
SqlCommand.Parameters.AddWithValue(@ Name,textbox.text);
try,
SqlCommand.CommandText = "SELECT * FROM students WHERE name= @Name";
SqlCommand.Parameters.AddWithValue("@Name", textbox.text);
这篇关于请帮助这个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!