我有一个正在运行的查询,我试图在屏幕上转储该查询,以便可以看到该查询并将其粘贴到我的SQL Server中。 (我曾经使用var_dump()在php中完成此操作)

我尝试在Console.Write()文件中使用aspx.cs。但是在浏览器上的开发工具中,控制台没有任何结果。

这是我的aspx按钮,

<asp:Button ID="btnSearch" runat="server" Text="GetEmails" onclick="btnSearch_Click" />


这是我在aspx.cs中的函数

protected void btnSearch_Click(object sender, EventArgs e)
{
    string query = "select * from tbl_inst";
    string queryWhere = " where time like '" + DropDownListTime.SelectedValue + "'";
    string loc= "";
    string room = "";

    if (!(loc= DropDownListLoc.SelectedValue).Equals(""))
    {
        queryWhere = " where (location1 like '" + loc + "%' or location2 like '" + loc + "%' or location3 like '" + loc + "%' or location4 like '" +
            loc + "%') and time like '" + DropDownListTime.SelectedValue + "'";
    }
    if (!(room = DropDownListRoom.SelectedValue).Equals(""))
    {
        queryWhere = " where (location1 like '" + room + "' or location2 like '" + room + "' or location3 like '" + room + "' or location4 like '" +
            room + "') and time like '" + DropDownListTime.SelectedValue + "'";
    }
    if (queryWhere.Contains("like ''")) { queryWhere = " where time is null"; }
    query += queryWhere;
    SqlDataSource1.SelectCommand = query;
}


基本上,我想在屏幕上的任何变量中看到这些值。

Console.WriteLine(room);
Console.WriteLine("TEST" + queryWhere);


等等..

最佳答案

要将数据转储到屏幕上(如您所要求的那样),可以使用Response.Write来完成。

Response.Write("TEST" + queryWhere);
Response.End(); // This will stop response, so that you can get the previously written data to response

关于c# - 如何在C#屏幕上转储数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26367432/

10-13 01:42