Mi ha sempre funzionato in questi giorni ma stamattina mi da quest'errore:
System.Data.OleDb.OleDbException: Per l'operazione è necessaria una query aggiornabile. in Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags) in Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack) in ASP.prova_aspx.InserisciDati(Object Source, EventArgs E) in c:\inetpub\wwwroot\prova.aspx:riga 37
Il codice è questo:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" debug="true"%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Oledb" %>
<script runat="server">
Sub Page_Load(Source as Object, E as EventArgs)
End Sub
Private ReadOnly Property StringaConnessione() As String
Get
Return "Provider=Microsoft.Jet.OLEDB.4.0;"& "Data Source=" & Server.MapPath("~/App_Data/collana.mdb")&""
End Get
End Property
Sub InserisciDati(Source as Object, E as EventArgs)
Dim cn
Dim str
Dim cmd
Dim icount As Integer
cn = New OleDbConnection(StringaConnessione)
Dim titolo = Request.Form("TextBox1")
Dim descrizione = Request.Form("TextBox2")
Try
cn.Open()
str = "INSERT INTO libri (titolo,descrizione) Values ('" & TextBox1.text & "', '" & TextBox2.text & "')"
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery()
' Response.Write(str)
Catch ex As Exception
'messaggio di errore
response.write(ex.tostring())
Finally
'chiusura connessione
Dim connessione
If (Not (Connessione Is Nothing)) Then Connessione.Close()
End Try
Label1.Text = "Database now updated"
End Sub
</script>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inserimento dati</title>
</head>
<body>
<div id="div1" >
<form action="registrazione.aspx" method="post" name="collana" id="collana" runat="server">
<table width="731" border="0" align="center">
<tr>
<td colspan="4" align="center" valign="middle">Iserimento dati</td>
</tr>
<tr>
<td width="168" align="center" valign="middle">Titolo</td>
<td colspan="3" align="left" valign="middle"><asp:TextBox ID="TextBox1" TextMode="SingleLine" runat="server" /><asp:RequiredFieldValidator ControlToValidate="TextBox1" ID="txtTextBox1" runat="server" Text="*Richesto" />
</td>
</tr>
<tr>
<td align="center" valign="middle">Descrizione</td>
<td colspan="3" align="left" valign="middle"><asp:TextBox ID="TextBox2" TextMode="SingleLine" runat="server" /><asp:RequiredFieldValidator ControlToValidate="TextBox2" ID="txtTextBox2" runat="server" Text="*Richesto" />
</td>
</tr>
<tr>
<td align="center" valign="middle">Inserisci</td>
<td colspan="3" align="left" valign="middle"><asp:Button ID="Button1" Text="Invia" runat="server" onClick="InserisciDati"/></td>
</tr>
</table>
</form>
<div id="div2" align="center"></div>
<asp:Label ID="label1" runat="server"></asp:Label>
</body>
</html>
Non riesco a capire il perchè?
il permesso di lettura e scrittura sul db è settato a everyone...
Mi date una mano per piacere?