Ho fatto una pagina delete.aspx, qui ho un asp:TextBox nel quale iserire l'id del record da eliminare, ma mi da quest'errore... Mi date una mano?
ciao e grazie anticipati.
System.Data.OleDb.OleDbException: Tipi di dati non corrispondenti nell'espressione criterio. 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.delete_aspx.EliminaDati(Object Source, EventArgs E) in c:\inetpub\wwwroot\delete.aspx:riga 34
<%@ 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 EliminaDati(Source as Object, E as EventArgs)
Dim cn
Dim str
Dim cmd
Dim icount As Integer
cn = New OleDbConnection(StringaConnessione)
Dim id = Request.Form("TextBox1")
Try
cn.Open()
str = "DELETE FROM libri WHERE id = '" & TextBox1.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 = "Record eliminato"
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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="registrazione.aspx" method="post" name="collana" id="collana" runat="server">
<table>
<tr>
<td width="168" align="left" valign="middle">Elimina record</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>
<td align="center" valign="middle"> </td>
<td colspan="3" align="left" valign="middle"><asp:Button ID="Button1" Text="Elimina" runat="server" onClick="EliminaDati"/></td>
</tr>
</table>
</form>
<asp:Label ID="label1" runat="server"></asp:Label>
</body>
</html>