How to display errors using Page_Error event of Page Object
VB.NET Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error Response.Write(Server.GetLastError().ToString) Server.ClearError() End Sub C# //In InitializeComponent this.Error += new System.EventHandler (this.Page_Error ); // private void Page_Error(object sender, System.EventArgs e ) { Response.Write(Server.GetLastError().ToString()); Server.ClearError (); } In the Same manner handle the Errors in the Application_Error event in global.asax
How to use OleDb DataReader
VB.NET Dim strConn As String = ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + Server.MapPath(‘nwind.mdb’) & ‘;’ Dim strsql As String = ‘Select * from Customers’ Dim cn As New OleDbConnection(strConn) Dim cmd As New OleDbCommand(strsql, cn) cn.Open() Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) DataGrid1.DataSource = dr DataGrid1.DataBind() C# string strConn = ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + Server.MapPath(‘nwind.mdb’) + ‘;’; string strsql = ‘Select * from Customers’; OleDbConnection cn = new OleDbConnection(strConn); OleDbCommand cmd = new OleDbCommand (strsql, cn); cn.Open (); OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection ); DataGrid1.DataSource = dr; DataGrid1.DataBind();
How to use OleDb DataSet
Use namespace System.Data.OleDb VB.NET Dim strConn As String = ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + Server.MapPath(‘nwind.mdb’) & ‘;’ Dim strsql As String = ‘Select * from Customers’ Dim cn As New OleDbConnection(strConn) Dim ds As DataSet = New DataSet() Dim da As New OleDbDataAdapter(strsql, cn) da.Fill(ds, ‘T1’) DataGrid1.DataSource = ds DataGrid1.DataBind() C# string strConn = ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + Server.MapPath(‘nwind.mdb’) + ‘;’; string strsql = ‘Select * from Customers’; OleDbConnection cn = new OleDbConnection(strConn); DataSet ds = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(strsql, cn); da.Fill(ds, ‘T1’); DataGrid1.DataSource = ds; DataGrid1.DataBind();
Are namespaces and Class names Case Sensitive
Namespaces and Class names are case Sensitive. Namespaces imported using the @ Import Directive will cause an error if the correct case is not used.
How to get the DataField name of a BoundColumn from code-behind
Try [VB.NET] Dim bc As BoundColumn = CType(Me.DataGrid1.Columns(1), BoundColumn) Response.Write(bc.DataField) [C#] BoundColumn bc = (BoundColumn)this.DataGrid1.Columns[1]; Response.Write(bc.DataField);