Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa noite pessoal, sou novato em programação ASP e preciso dar quebra de linha em um webservice:
segue script:
<%@ Page Language="C#" ContentType="text/json" Debug="true" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
//Dados de acesso ao banco SQL Server
string host = "localhost";
string usuario = "teste";
string senha = "teste";
string banco = "teste";
//Consulta SQL a ser efetuada
string strSQL = @"SELECT M.CODMOVIMENTO,M.CODTIPOMOVIMENTO,M.CODSTATUSMOVIMENTO,M.DATASTATUS
FROM MOVIMENTO M
WHERE M.CODTIPOMOVIMENTO=55001
AND M.CODSTATUSMOVIMENTO=5
AND CAST(M.DATASTATUS AS DATE) = CAST(GETDATE()-1 AS DATE)";
SqlConnection conexao = new SqlConnection("Data Source=" + host + ";DATABASE=" + banco + ";UID=" + usuario + "; PWD=" + senha + ";");
try
{
//Abre a conexão com o banco
conexao.Open();
try
{
SqlCommand comando = new SqlCommand(strSQL, conexao);
SqlDataReader dr = comando.ExecuteReader();
//Imprime os valores retornados na consulta
while (dr.Read())
{
Response.Write("{");
for (int i = 0; i < dr.FieldCount; i++)
{
Response.Write( dr.GetValue(i) );
if (i < dr.FieldCount-1) {
Response.Write(",");
}
}
Response.Write("}");
}
//Fecha o DataReader e libera os objetos para serem tratados pelo GC
dr.Close();
dr.Dispose();
comando.Dispose();
}
catch (Exception ex)
{
Response.Write("<br><font color='red'>Falha ao executar a consulta/procedimento SQL!</font><br>");
Response.Write(ex.ToString());
}
}
catch (Exception ex)
{
Response.Write("<br><font color='red'>Falha ao conectar-se na base de dados!</font><br>");
Response.Write(ex.ToString());
}
finally {
//Fecha a conexão do DataReader e depois do banco
conexao.Close();
conexao.Dispose();
}
}
</script>ele resulta em:
{304623001,55001,5,14/10/2016 17:52:04}{304624001,55001,5,14/10/2016 17:52:21}{304576001,55001,5,14/10/2016 17:36:06}{304597001,55001,5,14/10/2016 17:47:41}
me eu preciso que o resultado seja:
304623001,55001,5,14/10/2016 17:52:04
304624001,55001,5,14/10/2016 17:52:21
304576001,55001,5,14/10/2016 17:36:06
304597001,55001,5,14/10/2016 17:47:41
como faço isso?
Obrigado.
Lahedual
>
Nesta linha: Response.Write("}");
Você pode alterar para:
Response.Write("}<br>");
ou
Response.Write("}" & vbCrlf);
E talvez seja necessário criar um verificador no seu "loop" para não quebrar a linha quando imprimir o último registro.
Att.
Apliquei as duas soluções e erro:
Server Error in teste Application. *Runtime Error* **Description: **An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. **Details:** To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
**Notes:** The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File --> <configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
O que faço?>
Apliquei as duas soluções e erro:
Server Error in teste Application. Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
**Notes:** The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
<!-- Web.Config Configuration File --><configuration>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
</system.web>
</configuration>
O que faço?
Consegui fazer a quebra de linha com o comando
Response.Write("}" + Environment.NewLine);
Tem certeza q fez certo? Isso ae é .net, tem a seção apropriada para postar. Para mostrar a msg de erro, você deve seguir as instruções do retorno.
De qq forma tenta então deixar como estava e apenas acrescente a linha abaixo após a impressão da chave:
Response.Write("<br>");
Ficará algo como:
...
Response.Write("}");
Response.Write("<br>");
...
Att.
Preciso agora que o resultado
304623001,55001,5,14/10/2016 17:52:04
304624001,55001,5,14/10/2016 17:52:21
304576001,55001,5,14/10/2016 17:36:06
304597001,55001,5,14/10/2016 17:47:41
seja printado:
PEDIDO TIPO STATUS DATA 304576001 55001 5 14/10/2016 17:36 304597001 55001 5 14/10/2016 17:47 304623001 55001 5 14/10/2016 17:52 304624001 55001 5 14/10/2016 17:52 Como faço?
>
Preciso agora que o resultado
304623001,55001,5,14/10/2016 17:52:04
304624001,55001,5,14/10/2016 17:52:21
304576001,55001,5,14/10/2016 17:36:06
304597001,55001,5,14/10/2016 17:47:41
seja printado:
PEDIDO TIPO STATUS DATA 304576001 55001 5 14/10/2016 17:36 304597001 55001 5 14/10/2016 17:47304623001
55001 5 14/10/2016 17:52 304624001 55001 5 14/10/2016 17:52Como faço?
quero printar o resultado em uma tabela html
>
Tem certeza q fez certo? Isso ae é .net, tem a seção apropriada para postar. Para mostrar a msg de erro, você deve seguir as instruções do retorno.
De qq forma tenta então deixar como estava e apenas acrescente a linha abaixo após a impressão da chave:
Response.Write("<br>");
Ficará algo como:
...
Response.Write("}");
Response.Write("<br>");
...
Att.
Funcionou, obrigado.
>
Preciso agora que o resultado
304623001,55001,5,14/10/2016 17:52:04
304624001,55001,5,14/10/2016 17:52:21
304576001,55001,5,14/10/2016 17:36:06
304597001,55001,5,14/10/2016 17:47:41
seja printado:
PEDIDO TIPO STATUS DATA 304576001 55001 5 14/10/2016 17:36 304597001 55001 5 14/10/2016 17:47304623001
55001 5 14/10/2016 17:52 304624001 55001 5 14/10/2016 17:52Como faço?
Eu não manjo de .net - mas a lógica seria você tratar o resultado da consulta como um Array e fazer o loop em uma linha de tabela (tr), inserindo cada posição do Array em uma célula da linha da tabela (td).
Att
Nesta linha: Response.Write("}");
Você pode alterar para:
Response.Write("}<br>");
ou
Response.Write("}" & vbCrlf);
E talvez seja necessário criar um verificador no seu "loop" para não quebrar a linha quando imprimir o último registro.
Att.