1

我正在使用 C# 做一个 Ozeki Messenger 项目。我想从表中检索多条记录。它只给了我第一张唱片……

这是我的代码。任何想法做错了什么?

protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        String x;
        String y;
        String z;
        String SenderNumber, receiverNumber, message;
        SenderNumber = Request.QueryString.Get("sender");
        receiverNumber = Request.QueryString.Get("receiver");
        message = Request.QueryString.Get("msg");

        SqlConnection connection = new SqlConnection();
        SqlCommand command = new SqlCommand();
        SqlDataReader reader;

        connection.ConnectionString = Constring;
        command.Connection = connection;

        command.CommandText = "SELECT P_Name, P_Parking FROM tblPharmacy Where Code = '" + message + "'" ;

        connection.Open();

        reader = command.ExecuteReader();            
        String data = "";
        while (reader.Read())
        {
            x = reader["P_Name"].ToString();
            y = reader["P_Parking"].ToString();
            data += x + "  " + y + " - ";

            Response.Redirect("http://localhost:9333/ozeki?login=admin&password=xxxxxx&action=sendMessage&messagetype=SMS:TEXT&recepient=" + SenderNumber + " &messageData= " + data);
        }

        reader.Close();
        connection.Close();
    }
    catch (Exception)
    {
    }
}
4

1 回答 1

0

protected void Page_Load(object sender, EventArgs e) { try { String x; 字符串 y; 字符串 z; 字符串发送者编号、接收者编号、消息;SenderNumber = Request.QueryString.Get("sender"); receiverNumber = Request.QueryString.Get("receiver"); message = Request.QueryString.Get("msg");

    SqlConnection connection = new SqlConnection();
    SqlCommand command = new SqlCommand();
    SqlDataReader reader;

    connection.ConnectionString = Constring;
    command.Connection = connection;

    command.CommandText = "SELECT P_Name, P_Parking FROM tblPharmacy Where Code = '" + message + "'" ;

    connection.Open();

    reader = command.ExecuteReader();            
    String data = "";
    while (reader.Read())
    {
        x = reader["P_Name"].ToString();
        y = reader["P_Parking"].ToString();
        data += x + "  " + y + " - ";

    }

Response.Redirect(" http://localhost:9333/ozeki?login=admin&password=xxxxxx&action=sendMessage&messagetype=SMS:TEXT&recepient= " + SenderNumber + " &messageData= " + data); reader.Close(); 连接。关闭();} 捕捉(异常){ } }

我自己得到了答案..大声笑。Response.Redirect 应该在 While 循环之外。它工作得很好:D

于 2015-05-17T07:11:53.723 回答