Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    21

    [VB.Net]Problema connessione database

    Ciao!
    Avrei un problema:ho un sito scritto in asp e visual basic.net...il sito graficamente è a posto,manca solo una cosa:non riesco ad accedere al database,cioè vedere nel sito i dati che ho inserito nel mio database.
    Come posso fare?Quale codice devo scrivere?
    Grazie,ciao

  2. #2
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    "Non riesco ad accedere al database" che vuol dire?

    Non sai che codice scrivere?

    Hai scritto del codice e hai degli errori?

    E poi, di quale database parliamo?
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    21
    Allora...ho un sito di una azienda che fa software che tine conto delle modifiche effettuate dai vari collaboratori...è un sito semplicissimo con una pagina contenente un menu.Cliccando su ogni tab del menu dovrebbe saltare fuori una tabella che descrive le modifiche appunto.
    Il problema è che cliccando su ogni tab non solo non si vede nulla,ma con Firefox salta fuori:

    Server Error in '/' Application.
    HTTP Error 400 - Bad Request.

    Il database esiste,è stato scritto e creato con SQL Server Studio Express.

    Quindi il mio problema è quello di sapere che codice scrivere per poter vedere finalmente i miei dati sul sito.
    Spero di essere stato chiaro,ora.
    Grazie mille

  4. #4
    Utente di HTML.it L'avatar di oregon
    Registrato dal
    Jul 2005
    residenza
    Roma
    Messaggi
    36,480
    No che non lo sei stato e per questi motivi:

    1) il malfunzionamento/errore che hai indicato puo' essere determinato da tante cose, magari il db non c'entra

    2) "che codice scrivere per vedere" non e' una richiesta sensata ... non si sa nulla del codice, di cui parli e non si puo' dire dove intervenire ...
    No MP tecnici (non rispondo nemmeno!), usa il forum.

  5. #5
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    21
    Allora ti allego il codice dei due programmi.
    L'uno crea la pagina del sito,graficamente,ecc...,l'altro lo implementa ed esegue query sql per poter visualizzare i dati che voglio.
    Il primo programma:
    codice:
    <asp:UpdatePanel ID="updTab" runat="server">
       
            <ContentTemplate>
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                       <td style="width:50%" align="left" valign="bottom">
                            <div style="margin-left:30px; margin-top:0px; font-size:large; font-style:italic;">
                            <asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#0066cc" Text="Elenco richieste di modifica" />
                             </div>
                        </td>
     <td style="width:50%;" align="right">
    </tr>
                    <tr><td colspan="2" style="width:100%"></td></tr>
                </table>
    Queste sono le tab del menu :
    codice:
    <div id="navigation1">
                <ul>[*]<asp:HyperLink ID="Proposte" runat="server">Proposte</asp:HyperLink>[*]<asp:HyperLink ID="Approvate" runat="server">Approvate</asp:HyperLink>[*]<asp:HyperLink ID="Incorso" runat="server">In corso di sviluppo</asp:HyperLink>[*]<asp:HyperLink ID="Conclusi" runat="server">Lavori conclusi</asp:HyperLink>[*]<asp:HyperLink ID="Testati" runat="server">Lavori testati</asp:HyperLink>[*]<asp:HyperLink ID="Distribuiti" runat="server">Già distribuiti</asp:HyperLink>[*]<asp:HyperLink ID="Anomalie" runat="server">Tutte le anomalie rilevate</asp:HyperLink>[/list]
                </div>
    E questa ifnine,l'ultima parte che però non mi da alcun risultato a video :
    codice:
    <asp:SqlDataSource ID="dsRichieste" runat="server" ConnectionString="<%$ ConnectionStrings:NomeAzienda_NomeProgramma.My.MySettings.cnn %>">
                </asp:SqlDataSource>
    
                <asp:SqlDataSource ID="dsAnomalie" runat="server" ConnectionString="<%$ ConnectionStrings:NomeAzienda_NomeProgramma.My.MySettings.cnn %>">
                </asp:SqlDataSource>
    
                <div style="width: 100%; height:335px; overflow: auto;">
                    <asp:GridView ID="gProposte" runat="server" AllowPaging="True" AllowSorting="True" CaptionAlign="Left" CellPadding="1" DataSourceID="dsRichieste" Font-Size="Small" ForeColor="#333333" GridLines="None" CellSpacing="1" PageSize="100" Width="97%" AutoGenerateColumns="False">
                        <FooterStyle BackColor="#E0E0E0" Font-Bold="True" ForeColor="#404040" BorderColor="Gray" />
                        <RowStyle BackColor="#F7F6F3" Font-Size="Large" ForeColor="#333333" HorizontalAlign="Left" Wrap="True" VerticalAlign="Top" />
                        <EditRowStyle BackColor="Silver" Font-Size="XX-Small" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <PagerStyle BackColor="#E0E0E0" ForeColor="#404040" HorizontalAlign="Center" BorderColor="Gray" />
                        <HeaderStyle BackColor="#E0E0E0" Font-Bold="True" ForeColor="#404040" Wrap="False" BorderColor="Gray" />
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <PagerSettings FirstPageText="&lt;" LastPageText="&gt;" />
                        <Columns>
                            <asp:ImageField DataImageUrlField="Anomalia" ShowHeader="False">
                            </asp:ImageField>
                            <asp:BoundField DataField="ID" HeaderText="ID" />
                            <asp:BoundField DataField="Data" HeaderText="Data" />
                            <asp:BoundField DataField="Gruppo" HeaderText="Gruppo" />
                            <asp:BoundField DataField="Descrizione" HeaderText="Descrizione" />
                        </Columns>
                    </asp:GridView>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </asp:Content>

  6. #6
    Utente di HTML.it
    Registrato dal
    Aug 2008
    Messaggi
    21
    Il secondo programma:
    codice:
    Public Partial Class Richieste
        Inherits System.Web.UI.Page
    
        Protected Overrides Sub OnLoadComplete(ByVal e As System.EventArgs)
            MyBase.OnLoadComplete(e)
    
            imgProgramma.ImageUrl = "~/images/p-" + ImmagineProgramma()
            If TabRichieste.ActiveViewIndex < 0 Then TabRichieste.ActiveViewIndex = 6
        End Sub
    
        Protected Overrides Sub OnPreRenderComplete(ByVal e As System.EventArgs)
            MyBase.OnPreRenderComplete(e)
    
            Proposte.NavigateUrl = "\Richieste.aspx?IDSw=" + CStr(Me.Request.QueryString("IDSW")) + _
                                                  "&Stato=1"
    
            Approvate.NavigateUrl = "\Richieste.aspx?IDSw=" + CStr(Me.Request.QueryString("IDSW")) + _
                                                  "&Stato=2"
    
            Incorso.NavigateUrl = "\Richieste.aspx?IDSw=" + CStr(Me.Request.QueryString("IDSW")) + _
                                                  "&Stato=3"
    
            Conclusi.NavigateUrl = "\Richieste.aspx?IDSw=" + CStr(Me.Request.QueryString("IDSW")) + _
                                                  "&Stato=4"
    
            Testati.NavigateUrl = "\Richieste.aspx?IDSw=" + CStr(Me.Request.QueryString("IDSW")) + _
                                                  "&Stato=5"
    
            Distribuiti.NavigateUrl = "\Richieste.aspx?IDSw=" + CStr(Me.Request.QueryString("IDSW")) + _
                                                  "&Stato=7"
    
            Anomalie.NavigateUrl = "\Richieste.aspx?IDSw=" + CStr(Me.Request.QueryString("IDSW")) + _
                                                  "&Stato=0"
    
            dsRichieste.SelectCommand = Sql_Richieste()
            dsAnomalie.SelectCommand = Sql_Anomalie()
            
        End Sub
    
        Private Function ImmagineProgramma() As String
            Dim cnn As New SqlClient.SqlConnection(My.Settings.cnn) : cnn.Open()
            Dim cmd As New SqlClient.SqlCommand("Select immagine From Software Where IDSw = " + CStr(CInt(Me.Request.QueryString("IDSW"))), cnn)
            Try
                Return CStr(cmd.ExecuteScalar)
            Catch ex As Exception
                Return ""
            Finally
                cnn.Close()
                cnn.Dispose()
                cmd.Dispose()
            End Try
    
        End Function
    
        Private Function Sql_Richieste() As String
        Dim sw As Integer = CInt(Me.Request.QueryString("IDSW"))
            Dim Stato As Byte = 1
            If Me.Request.QueryString("Stato") IsNot Nothing Then _
               Stato = CByte(Me.Request.QueryString("Stato"))
            Dim o As Object = TabRichieste.Controls(TabRichieste.ActiveViewIndex)
            If o Is vProposte Then
                Stato = 1
            ElseIf o Is vApprovate Then
                Stato = 2
            ElseIf o Is vInCorso Then
                Stato = 3
            ElseIf o Is vConcluse Then
                Stato = 4
            ElseIf o Is vTestate Then
                Stato = 5
            ElseIf o Is vDistribuite Then
                Stato = 7
            End If
    
            Return _
            "Select case when R.Tipo = 0                                " + vbCrLf + _
            "            then '~/images/Anomalia.gif'                   " + vbCrLf + _
            "            else null                                      " + vbCrLf + _
            "        end                                    as Anomalia " + vbCrLf + _
            "     , R.ID                                                " + vbCrLf + _
            "     , case R.Stato                                        " + vbCrLf + _
            "        when 1 then dbo.md_F_ValToDate(R.DataRic)			" + vbCrLf + _
            "        when 2 then dbo.md_F_ValToDate(R.DataApp)			" + vbCrLf + _
            "        when 3 then dbo.md_F_ValToDate(R.DataIni)			" + vbCrLf + _
            "        when 4 then dbo.md_F_ValToDate(R.DataCon)	 		" + vbCrLf + _
            "        when 5 then dbo.md_F_ValToDate(R.DataTest)		    " + vbCrLf + _
            "        when 7 then dbo.md_F_ValToDate(R.DataDis)			" + vbCrLf + _
            "        else ''                                            " + vbCrLf + _
            "        end                                    as [Data]   " + vbCrLf + _
            "     , R.Gruppo                                            " + vbCrLf + _
            "     + case when len(R.SottoGruppo) > 0                    " + vbCrLf + _
            "            then ' - ' + R.SottoGruppo                     " + vbCrLf + _
            "            else ''                                        " + vbCrLf + _
            "        end									as [Gruppo] " + vbCrLf + _
            "     , R.Descrizione                                       " + vbCrLf + _
            "  from Richieste R                                         " + vbCrLf + _
            " where R.IDSw  = " + CStr(sw) + "                          " + vbCrLf + _
            "   and R.Stato = " + CStr(Stato) + "                       " + vbCrLf + _
            "order by case R.Stato                                      " + vbCrLf + _
            "           when 1 then R.DataRic		                    " + vbCrLf + _
            "           when 2 then R.DataApp		                    " + vbCrLf + _
            "           when 3 then R.DataIni		                    " + vbCrLf + _
            "           when 4 then R.DataCon		                    " + vbCrLf + _
            "           when 5 then R.DataTest		                    " + vbCrLf + _
            "           when 7 then R.DataDis		                    " + vbCrLf + _
            "           else 0                                          " + vbCrLf + _
            "        end desc                                           " + vbCrLf + _
            "    , R.ID                                                 "
    
        End Function
    
        Private Function Sql_Anomalie() As String
            Dim sw As Integer = CInt(Me.Request.QueryString("IDSW"))
    
            Return _
            "Select R.ID                                                " + vbCrLf + _
            "     , case R.Stato                                        " + vbCrLf + _
            "        when 1 then dbo.md_F_ValToDate(R.DataRic)			" + vbCrLf + _
            "        when 2 then dbo.md_F_ValToDate(R.DataApp)			" + vbCrLf + _
            "        when 3 then dbo.md_F_ValToDate(R.DataIni)			" + vbCrLf + _
            "        when 4 then dbo.md_F_ValToDate(R.DataCon)			" + vbCrLf + _
            "        when 5 then dbo.md_F_ValToDate(R.DataTest)			" + vbCrLf + _
            "        when 7 then dbo.md_F_ValToDate(R.DataDis)			" + vbCrLf + _
            "        else ''                                            " + vbCrLf + _
            "        end                                    as [Data]   " + vbCrLf + _
            "     , S.Descrizione                           as Stato    " + vbCrLf + _
            "     , R.Gruppo                                            " + vbCrLf + _
            "     + case when len(R.SottoGruppo) > 0                    " + vbCrLf + _
            "            then ' - ' + R.SottoGruppo                     " + vbCrLf + _
            "            else ''                                        " + vbCrLf + _
            "        end									as [Gruppo] " + vbCrLf + _
            "     , R.Descrizione                                       " + vbCrLf + _
            "From Richieste R                                           " + vbCrLf + _
            "        inner join Stati S                                 " + vbCrLf + _
            "        on R.Stato = S.Stato                               " + vbCrLf + _
            "Where R.IDSw  = " + CStr(sw) + "                           " + vbCrLf + _
            "   and R.Stato <> 0   -- Non approvate                     " + vbCrLf + _
            "   and R.Stato <> 1   -- Proposte                          " + vbCrLf + _
            "   and R.Stato <> 6   -- Rimandate                         " + vbCrLf + _
            "   and R.Stato <> 7   -- Distribuite                       " + vbCrLf + _
            "   and R.Stato <> 10  -- Eliminate                         " + vbCrLf + _
            "   and R.Tipo  = 0    -- Solo le anomalie                  " + vbCrLf + _
            "Order by case R.Stato                                      " + vbCrLf + _
            "           when 1 then R.DataRic		                    " + vbCrLf + _
            "           when 2 then R.DataApp		                    " + vbCrLf + _
            "           when 3 then R.DataIni		                    " + vbCrLf + _
            "           when 4 then R.DataCon		                    " + vbCrLf + _
            "           when 5 then R.DataTest		                    " + vbCrLf + _
            "           when 7 then R.DataDis		                    " + vbCrLf + _
            "           else 0                                          " + vbCrLf + _
            "        end desc                                           " + vbCrLf + _
            "    , R.ID                                                 "
        End Function
    
    
        Private Sub TabRichieste_ActiveViewChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabRichieste.ActiveViewChanged
            Dim o As Object = TabRichieste.Controls(TabRichieste.ActiveViewIndex)
            gProposte.Visible = True
            If Not (o Is vAnomalie) Then Exit Sub
    
            gProposte.Visible = False
        End Sub
    End Class
    Ecco,questi sono i due programmi principali che uso per questo sito.Il risultato a video è un menu con 7 tab,ognuna "vuota"...cliccandoci sopra l'errore che mi fornisce è quello che ho detto prima.In teoria invece dovrebbe aprirmi una tabella con all'interno dei dati presi da database
    Grazie ancora !!

  7. #7
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,320

    Moderazione

    Quando si posta il codice, questo va fatto all'interno degli appositi tag [code] e [/code] (come indicato esplicitamente nel regolamento), altrimenti, come avrai visto tu stesso, il tutto risulta illeggibile, perdendo in formattazione e indentazione.

    Correggo io i tuoi ultimi post, se possibile.


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.