命令文本,文本框 [英] Command Text, Textbox

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

问题描述

此代码正确吗?

Is this code correct?

SqlCommand cmd = new SqlCommand();

cmd.Connection = cn;
cmd.CommandType=CommandType.Text
cmd.CommandText= "SELECT * FROM Orders2 WHERE Monthname = '" + textBox1.Text.ToString() + "' AND '" + textBox2.Text.ToString() + "'" 



在预先感谢



Thanks in Advance

推荐答案

cmd.CommandText= "SELECT * FROM Orders2 WHERE Monthname = '" + textBox1.Text + "' AND Monthname = '" + textBox2.Text + "'"; 


不,这是不正确的
No it''s not correct
/*...*/"WHERE Monthname = '" + textBox1.Text.ToString() + "' AND '" + textBox2.Text.ToString() + "'"


:confused:

使用AND运算符时,这将是正确的命令:


:confused:

That will be the correct command when you are using AND operator:

cmd.CommandText = "SELECT * FROM Orders2 WHERE Monthname = '" + textBox1.Text + "' AND  Monthname ='" + textBox2.Text + "'";


:)


据我所知,这看起来还可以.
As far as I know, this looks ok.


这篇关于命令文本,文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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