|
xxx
VB to C# Conversion
by Jeffrey Schoolcraft
Here is VB code.
filename=/students/jeffschoolcraft/executescalar.aspx
<%@ Import Namespace="System.Data.OLEDB" %>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
Dim strConn as string ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\data\biblio.mdb;"
Dim strSQL as string ="select count(*) from publishers where state='NY'"
Dim Conn as OLEDBConnection
Dim Cmd as OLEDBCommand
TRY
Conn = New OLEDBConnection(strConn)
Cmd = New OLEDBCommand(strSQL,Conn)
Conn.Open()
litHowMany.text=cmd.executescalar()
CATCH e1 as exception
litError.text = e1.Message
FINALLY
Conn.Close()
END TRY
End Sub
</script>
<html><head>
<title>Grid of New York Data</title>
</head>
<body bgcolor="#FFFFFF">
<asp:literal id="litError" runat="server" />
<font face="Verdana"><h3>New York Count</h3></font>
New York has <ASP:Literal id="litHowMany" runat="server"/> records
</body></html>
Now for the C# Code:
filename=/students/jeffschoolcraft/executescalarcs.aspx
<%@ Import Namespace="System.Data.OleDb" %>
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
string strConn=@"PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("/experiments/data/biblio.mdb") + ";";
string strSQL="select count(*) from publishers where state='NY'";
// OleDbConnection Conn;
OleDbConnection Conn = new OleDbConnection(strConn);
OleDbCommand Cmd;
try
{
// Conn = new OleDbConnection(strConn);
Cmd = new OleDbCommand(strSQL,Conn);
Conn.Open();
litHowMany.Text=Cmd.ExecuteScalar().ToString();
}
catch (Exception e1)
{
litError.Text = e1.Message;
}
finally
{
Conn.Close();
}
}
</script>
<html><head>
<title>Grid of New York Data</title>
</head>
<body bgcolor="#FFFFFF">
<asp:literal id="litError" runat="server" />
<font face="Verdana"><h3>New York Count</h3></font>
New York has <ASP:Literal id="litHowMany" runat="server"/> records
</body></html>
 |  |  |
 |
There are many worthy charities!!. But perhaps help starving children in Africa or South America AND help Charles too.
a $5 tip buys him lunch at McDonalds,
a $20 tip buys his kid Hitoshi a new computer game,
a $39 tip buys his daughter Michiko a few nice outfits.
See our donor list.
|  |
 |  |  |
|
|
|
|