<%@ 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
dgData.DataSource = objReader
dgData.DataBind()
objReader.Close
objCmd.Connection.Close()
catch objEx as FormatException
lblMessage.Text = objEx.Message
catch objEx as OleDbException
lblMessage.Text = "Database error!"
catch objEx as Exception
lblMessage.Text = "Unknown error!"
end try
end sub
</script>
<html><body>
<form runat="server">
<asp:Label id="lblMessage" runat="server"
maintainstate=false /><br>
Enter an ID: <asp:TextBox id="tbID" runat="server"
AutoPostBack=True
OnTextChanged=GetData />
<asp:DataGrid id="dgData" runat="server"
BorderColor="black"
GridLines="Vertical"
width="100%"
Font-Name="Arial"
Font-Size="8pt"
HeaderStyle-BackColor="#cccc99"
ItemStyle-BackColor="#ffffff"
AlternatingItemStyle-Backcolor="#cccccc"
AutoGenerateColumns="true" />
</form>
</body></html>
|