<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
'declare connection
dim Conn as new OleDbConnection( _
"PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("EmployeeDatabase.mdb;"))
sub GetData(Sender as Object, e as EventArgs)
dim objCmd as OleDbCommand = new OleDbCommand _
("select * from employee where ID = @ID", Conn)
dim objReader as OleDbDataReader
dim objParam as OleDbParameter
objParam = objCmd.Parameters.Add("@ID", OleDbType.Integer)
objParam.Direction = ParameterDirection.Input
objParam.Value = tbID.Text
try
objCmd.Connection.Open()
objReader = objCmd.ExecuteReader
catch ex as OleDbException
Label1.Text = "Error retrieving from the database."
end try
DataGrid1.DataSource = objReader
DataGrid1.DataBind()
objReader.Close
objCmd.Connection.Close()
end sub
</script>
<html><body>
<form runat="server">
<asp:Label id="Label1" runat="server"
maintainstate=false /><br>
Enter an ID: <asp:TextBox id="tbID" runat="server"
AutoPostBack=True
OnTextChanged=GetData />
<asp:DataGrid id="DataGrid1" runat="server"
BorderColor="black"
width="100%"
AutoGenerateColumns="true" />
</form>
</body></html>
|