codice:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Private StringaConnessione As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dati\test\test.mdb"
Sub GetData(ByVal obj As Object, ByVal e As EventArgs)
Dim objCon As OleDb.OleDbConnection = Nothing
Dim objCmd As OleDbCommand = Nothing
Dim objReader As OleDbDataReader = Nothing
Try
objCon = New OleDbConnection(StringaConnessione)
objCon.Open()
objCmd = objCon.CreateCommand()
objCmd.CommandText = "SELECT * FROM [campi] WHERE id = ? "
objCmd.Parameters.Clear()
objCmd.Parameters.Add("id", OleDbType.Integer).Value = Me.tbCodice.Text
objReader = objCmd.ExecuteReader()
DataGrid1.DataSource = objReader
DataGrid1.DataKeyField = "id"
DataGrid1.DataBind()
Catch ex As OleDbException
Label1.Text = "Errore dal database."
Finally
If objReader IsNot Nothing Then objReader.Close()
If objCon IsNot Nothing Then objCon.Close()
End Try
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Verdana, Helvetica, sans-serif;
font-size: 8pt;
}
#tbCodice {border:1px gray solid;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" />
Inserisci un Codice:
<asp:TextBox ID="tbCodice" runat="server" AutoPostBack="true" OnTextChanged="GetData" />
<asp:DataGrid ID="DataGrid1" runat="server" BorderColor="black" GridLines="Vertical" Width="100%" Font-Names="Arial" Font-Size="8pt" HeaderStyle-BackColor="#cccc99" ItemStyle-BackColor="#ffffff" AlternatingItemStyle-BackColor="#cccccc" AutoGenerateColumns="true" />
</p>
</div>
</form>
</body>
</html>
che libro è?