

lahedual
Members-
Content count
8 -
Joined
-
Last visited
Community Reputation
0 ComumAbout lahedual

-
ok, vou estudar isso, obrigado.
- 2 replies
-
- web service
- html
-
(and 1 more)
Tagged with:
-
Boa noite! Sou novo em programação e estou montando um webservice, mas preciso que o consumo da consulta seja tabulado em formato de tabela no navegador, como faço? abaixo segue o 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"; int codmovimento = Convert.ToInt32(Request.QueryString["codmovimento"]); //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("" + Environment.NewLine ); } //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>
- 2 replies
-
- web service
- html
-
(and 1 more)
Tagged with:
-
Funcionou, obrigado.
-
quero printar o resultado em uma tabela html
-
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?
-
Consegui fazer a quebra de linha com o comando Response.Write("}" + Environment.NewLine);
-
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?
-
lahedual started following Quebra de linha
-
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