Probleem met inserten in database

Status
Niet open voor verdere reacties.

xenium

Gebruiker
Lid geworden
1 jul 2007
Berichten
148
Hey,

Voor school dienen wij een project te maken (volledig drie lagig), maar er zijn enkele problemen:

Onderste laag: connectielaag (alle sql en connectiestring)
Middelste laag: vb file achter de aspx pagina
Bovenste laag: aspx pagina

Productie_toevoegen.aspx:

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="productie_toevoegen.aspx.vb" Inherits="productie_toevoegen" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td style="height: 21px; width: 150px;">Titel:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtTitel" runat="server" Width="350px" MaxLength="50"></asp:TextBox></td>
            </tr>
            <tr>
                <td style="height: 21px; width: 150px;">Regie:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtRegie" runat="server" Width="350px" MaxLength="50"></asp:TextBox></td>
            </tr> 
           <tr>
                <td style="height: 21px; width: 150px;">Scenarioschrijver:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtAuteur" runat="server" Width="350px" MaxLength="75"></asp:TextBox></td>
           </tr>
           <tr>
                <td style="height: 21px; width: 150px;">Beschrijving:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtBeschrijving" runat="server" Width="350px" Rows="5" TextMode="MultiLine"></asp:TextBox></td>
           </tr>
           <tr>
                <td style="height: 21px; width: 150px;">Cast:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtCast" runat="server" Width="350px"></asp:TextBox></td>
           </tr>
           <tr>
                <td style="height: 21px; width: 150px;">Prijs:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtPrijs" runat="server" Width="350px"></asp:TextBox></td>
           </tr>
           <tr>
                <td style="height: 21px; width: 150px;">Seizoen:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:DropDownList ID="cmbSeizoensID" runat="server" DataSourceID="AccessDataSource1"
                        DataTextField="Naam" DataValueField="SeizoenID" Width="350px">
                    </asp:DropDownList><asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Schoolbond.mdb"
                        SelectCommand="SELECT [SeizoenID], [Naam] FROM [tblSeizoenen]">
                    </asp:AccessDataSource>
                </td>
           </tr>
           <tr>
                <td></td>
                <td style="width: 350px">
                    <asp:Button ID="cmdOpslagen" runat="server" Text="Opslaan productie" Width="350px" OnClick="opslaan_productie" /></td>
           </tr>
        </table>   
    </div>
    </form>
</body>
</html>

Het gaat over de asp button cmdOpslagen

Code van productie_toevoegen.aspx.vb:

Code:
Imports System
Imports System.Data
Imports Schoolbond


Partial Class productie_toevoegen
    Inherits System.Web.UI.Page

    Sub opslaan_productie(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
        Dim data As Connectie
        data.opslaan_productie(Me.txtTitel, Me.txtRegie, Me.txtAuteur, Me.txtBeschrijving, Me.txtCast, Me.txtPrijs, Me.cmbSeizoensID)
    End Sub
End Class

Als ik dit zo laat runnen krijg ik de foutmelding dat Me.txtTitel, Me.txtRegie, Me.txtAuteur, Me.txtBeschrijving, Me.txtCast, Me.txtPrijs, Me.cmbSeizoensID niet kunnen geconverteerd worden naar string, integer, boolean, double, ...

Dus heb dan het volgende gedaan (productie_toevoegen.aspx.vb):

Code:
Imports System
Imports System.Data
Imports Schoolbond


Partial Class productie_toevoegen
    Inherits System.Web.UI.Page

    Private theTitel As String
    Private theRegie As String
    Private theAuteur As String
    Private theBeschrijving As String
    Private theCast As String
    Private thePrijs As Double
    Private theSeizoenID As Integer


    Public Property Titel() As String
        Get
            Return Me.theTitel
        End Get
        Set(ByVal value As String)
            Me.theTitel = value
        End Set
    End Property

    Public Property Regie() As String
        Get
            Return Me.theRegie
        End Get
        Set(ByVal value As String)
            Me.theRegie = value
        End Set
    End Property

    Public Property Auteur() As String
        Get
            Return Me.theAuteur
        End Get
        Set(ByVal value As String)
            Me.theAuteur = value
        End Set
    End Property

    Public Property Beschrijving() As String
        Get
            Return Me.theBeschrijving
        End Get
        Set(ByVal value As String)
            Me.theBeschrijving = value
        End Set
    End Property

    Public Property Cast() As String
        Get
            Return Me.theCast
        End Get
        Set(ByVal value As String)
            Me.theCast = value
        End Set
    End Property

    Public Property Prijs() As Double
        Get
            Return Me.thePrijs
        End Get
        Set(ByVal value As Double)
            Me.thePrijs = value
        End Set
    End Property

    Public Property SeizoenID() As Integer
        Get
            Return Me.theSeizoenID
        End Get
        Set(ByVal value As Integer)
            Me.theSeizoenID = value
        End Set
    End Property

    Public Sub New(ByVal anID As Integer, ByVal aTitel As String, ByVal aRegie As String, ByVal anAuteur As String, ByVal aBeschrijving As String, ByVal aCast As String, ByVal aPrijs As Double, ByVal aSeizoensID As Integer)
        'Me.theProductieID = anID
        Me.theTitel = aTitel
        Me.theRegie = aRegie
        Me.theAuteur = anAuteur
        Me.theBeschrijving = aBeschrijving
        Me.theCast = aCast
        Me.thePrijs = aPrijs
        Me.theSeizoenID = aSeizoensID
    End Sub

    Sub opslaan_productie(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim data As Connectie
        data.opslaan_productie(Me.theTitel, Me.theRegie, Me.theAuteur, Me.theBeschrijving, Me.theCast, Me.thePrijs, Me.theSeizoenID)
        'data.opslaan_productie(Me.theTitel, Me.theRegie, Me.theAuteur, Me.theBeschrijving, Me.theCast, Me.thePrijs, Me.theSeizoenID)
    End Sub
End Class

Nu krijg ik de foutmelding dat hij eerst 'public sub new' moet uitvoeren. De code van 'sub opslaan_productie' heb ik reeds bij de sub new gezet, maar nog werkt dit niet.

Iemand enig idee...
 
Update van fouten:

productie_toevoegen.aspx:

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="productie_toevoegen.aspx.vb" Inherits="productie_toevoegen" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td style="height: 21px; width: 150px;">Titel:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtTitel" runat="server" Width="350px" MaxLength="50"></asp:TextBox></td>
            </tr>
            <tr>
                <td style="height: 21px; width: 150px;">Regie:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtRegie" runat="server" Width="350px" MaxLength="50"></asp:TextBox></td>
            </tr> 
           <tr>
                <td style="height: 21px; width: 150px;">Scenarioschrijver:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtAuteur" runat="server" Width="350px" MaxLength="75"></asp:TextBox></td>
           </tr>
           <tr>
                <td style="height: 21px; width: 150px;">Beschrijving:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtBeschrijving" runat="server" Width="350px" Rows="5" TextMode="MultiLine"></asp:TextBox></td>
           </tr>
           <tr>
                <td style="height: 21px; width: 150px;">Cast:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtCast" runat="server" Width="350px"></asp:TextBox></td>
           </tr>
           <tr>
                <td style="height: 21px; width: 150px;">Prijs:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:TextBox ID="txtPrijs" runat="server" Width="350px"></asp:TextBox></td>
           </tr>
           <tr>
                <td style="height: 21px; width: 150px;">Seizoen:</td>
                <td style="height: 21px; width: 350px;">
                    <asp:DropDownList ID="cmbSeizoensID" runat="server" DataSourceID="AccessDataSource1"
                        DataTextField="Naam" DataValueField="SeizoenID" Width="350px">
                    </asp:DropDownList><asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Schoolbond.mdb"
                        SelectCommand="SELECT [SeizoenID], [Naam] FROM [tblSeizoenen]">
                    </asp:AccessDataSource>
                </td>
           </tr>
           <tr>
                <td></td>
                <td style="width: 350px">
                    <asp:Button ID="cmdOpslagen" runat="server" Text="Opslaan productie" Width="350px" OnClick="opslaan_productie" /></td>
           </tr>
        </table>   
    </div>
    </form>
</body>
</html>

productie_toevoegen.aspx.vb:

Code:
Imports System
Imports System.Data
Imports Schoolbond


Partial Class productie_toevoegen
    Inherits System.Web.UI.Page

    Sub opslaan_productie(ByVal Sender As Object, ByVal E As EventArgs)
        Dim data As Connectie
        'data.opslaan_productie(Me.txtTitel, Me.txtRegie, Me.txtAuteur, Me.txtBeschrijving, Me.txtCast, Me.txtPrijs, Me.cmbSeizoensID)
        data.opslaan_productie(Convert.ToString(Me.txtTitel), Convert.ToString(Me.txtRegie), Convert.ToString(Me.txtAuteur), Convert.ToString(Me.txtBeschrijving), Convert.ToString(Me.txtCast), Convert.ToDouble(Me.txtPrijs), Convert.ToInt32(Me.cmbSeizoensID))
    End Sub
End Class


Krijg dan de volgende foutmelding:

System.InvalidCastException was unhandled by user code
Message="Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.IConvertible'."
Source="mscorlib"
StackTrace:
at System.Convert.ToDouble(Object value)
at productie_toevoegen.opslaan_productie(Object Sender, EventArgs E) in C:\school\test2 of eTicket Nightly\productie_toevoegen.aspx.vb:line 12
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Nu vroeg ik me af of iemand weet wat hier het probleem is.

Alvast bedankt
 
Ik heb wat opmerkingen:

1: Dim data As Connectie
Ik neem aan dat Connectie een object uit de data-laag is, die zijn oorsprong vindt in Imports Schoolbond

2:
data.opslaan_productie(Convert.ToString(Me.txtTitel) ...
data.opslaan_productie(Me.txtTitel ...

Ik weet niet hoe de methode/functie opslaan_productie in Connectie is gedefinieerd, maar meestal worden alleen waarden doorgegeven, en niet de hele objecten:
Me.txtTitel is het hele TextBox-object.
Me.txtTitel.Text is de waarde die ingevuld is in het object.

Na Convert.ToString(Me.txtTitel) krijg je de foutmelding :
Message="Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.IConvertible'."
In andere woorden : "Ik kan het object TextBox niet vertalen/omzetten naar een tekst".

dus probeer het eens met :
data.opslaan_productie(Me.txtTitel.Text, Me.txtRegie.Text, Me.txtAuteur.Text, Me.txtBeschrijving.Text, Me.txtCast.Text, Me.txtPrijs.Text, Me.cmbSeizoensID.Text)


afhankelijk van de functie definitie van "opslaan_productie" zal je de waarde van Me.cmbSeizoensID.Text nog moeten casten/parsen naar een integer en Me.txtPrijs.Text naar een decimal oid.
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan