I am working with OLEDB for Access, my following code in VB worked
but the same code (converted) in C# isnt working.
Code in VB
<% @ Page Language="VB" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OLEDB" %>
<html>
<script runat = server>
Sub Page_Load(Src As Object, E As EventArgs)
Dim strConn as string ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=" & server.mappath("dbase3.mdb") & ";"
Dim strSQL as string ="select * from Factory1 order by Period"
Dim Conn as New OLEDBConnection(strConn)
Dim Cmd as New OLEDBCommand(strSQL,Conn)
Dim Rdr as OLEDBDataReader
Conn.Open()
Rdr=Cmd.ExecuteReader()
MyDataGrid.DataSource = Rdr
MyDataGrid.DataBind()
Rdr.close()
Conn.close()
End Sub
</script>
Code in C#
<% @ Page Language="C#" %>
<% @ Import Namespace="System.Data" %>
<% @ Import Namespace="System.Data.OleDb" %>
<html>
<script language="C#" runat="server">
void Page_Load(Object Src,EventArgs E) {
string strConn ="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=dbase3.mdb;" ;
string strSQL ="select * from Factory1 order by Period";
OleDbConnection Conn = new OleDbConnection(strConn);
OleDbCommand Cmd = new OleDbCommand(strConn, Conn);
OleDbDataReader Rdr;
Conn.Open();
Rdr=Cmd.ExecuteReader();
MyDataGrid.DataSource = Rdr;
MyDataGrid.DataBind();
Rdr.close();
Conn.close();
}
</script>
When I am trying to execute the C# pgm removing some statements, my
program is working correctly until the statement above Conn.Open();
Apparently, the error should be somewhere in Conn.Open();
But I couldnt figure out as the syntax is fine.
Hope someone can help me.