where子句不与orded一起使用 [英] where clause not working with orded by

查看:124
本文介绍了where子句不与orded一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string sql1 = "Select * from callpad_def where read_status=@read ORDER BY time_stamp DESC";
SqlCommand cmd = new SqlCommand(sql1, con);
SqlDataReader sqlReader = cmd.ExecuteReader();
while (sqlReader.Read())
{
    c_address =Convert.ToInt32(sqlReader.GetValue(0).ToString());
    c_status = sqlReader.GetValue(1).ToString();
    token_no = (sqlReader.GetValue(2).ToString());
    if (c_status != null)
    {
        status_reader(c_status);
    }
}
sqlReader.Close();

推荐答案

您需要编写查询,例如



You need to write query such as

"Select * from callpad_def where read_status=" + 'read' + "ORDER BY time_stamp DESC"


修改您的查询,例如,



这里读取的是一个变量,所以你就像这样传递它的值..



从callpad_def中选择*,其中read_status = +读+ORDER BY time_stamp DESC;



谢谢



快乐编码...
Modify your query such as,

here read is a variable so you passed its value like this way..

"Select * from callpad_def where read_status=" + read + "ORDER BY time_stamp DESC";

Thanks

Happy coding...


String readValue;
string sql1 = "Select * from callpad_def where read_status=@read ORDER BY time_stamp DESC";
                SqlCommand cmd = new SqlCommand(sql1, con);
                cmd.Parameters.AddWithValue("@read", readValue);
                SqlDataReader sqlReader = cmd.ExecuteReader();
                while (sqlReader.Read())
                {
                    c_address =Convert.ToInt32(sqlReader.GetValue(0).ToString());
                    c_status = sqlReader.GetValue(1).ToString();
                    token_no = (sqlReader.GetValue(2).ToString());
                    if (c_status != null)
                    {
                        status_reader(c_status);
                    }
                }
                sqlReader.Close();


这篇关于where子句不与orded一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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