indsætte data i access finde fejlen
HejJeg har siddet og rodet med en enkel side i web matrix, som via en formular skal kunne upload data til en access database.
Men jeg kan ikke finde fejlen, håber en vil hjælpe med dette
<%@ Page Language="VB" ClassName="test" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<script runat="server">
Function MyQueryMethod() As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\adresser.mdb"
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
Dim queryString As String = "SELECT [medlemmer].* FROM [medlemmer]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
Function MyInsertMethod(ByVal navn As Integer, ByVal efternavn As Integer) As Integer
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Documents an"& _
"d Settings\KBS\Skrivebord\adresser.mdb"
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
Dim queryString As String = "INSERT INTO [medlemmer] ([navn], [efternavn]) VALUES (@navn, @efternavn)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_navn As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_navn.ParameterName = "@navn"
dbParam_navn.Value = navn
dbParam_navn.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_navn)
Dim dbParam_efternavn As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
dbParam_efternavn.ParameterName = "@efternavn"
dbParam_efternavn.Value = efternavn
dbParam_efternavn.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_efternavn)
Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try
Return rowsAffected
End Function
Sub cmdOpret_Click(sender As Object, e As EventArgs)
Dim navn As string
Dim efternavn As string
navn= Server.HtmlEncode (navn)
efternavn= Server.HtmlEncode (efternavn)
Try
MyInsertMethod (navn, efternavn)
labelMessage.Text= "sucess"
cmdOpret.Enabled = False
Catch
labelMessage.Text= "Please submit again there was an error"
End Try
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:Label id="eNavn" runat="server">Fornavn</asp:Label>
<asp:TextBox id="navn" runat="server"></asp:TextBox>
</p>
<p>
<asp:Label id="eEfternavn" runat="server">Efternavn</asp:Label>
<asp:TextBox id="efternavn" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="cmdOpret" onclick="cmdOpret_Click" runat="server" Text="Button" CommandName="addButton"></asp:Button>
</p>
<p>
<asp:Label id="labelMessage" runat="server"></asp:Label>
</p>
<p>
</p>
<!-- Insert content here -->
</form>
</body>
</html>