Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 9th, 2005, 06:53 AM
Authorized User
 
Join Date: Oct 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to richie86
Default Database unable to show result. (ASP.NET C#)

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

namespace HoangYuh
{

    public class _Default : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Label lblNotice;
        protected System.Web.UI.WebControls.Label lblName;
        protected System.Web.UI.WebControls.Label lblNameList;
        protected System.Web.UI.WebControls.Label lblPostCount;
        protected System.Web.UI.WebControls.Label Label1;
        protected System.Web.UI.WebControls.Button btnForum;

        private void Page_Load(object sender, System.EventArgs e)
        {
            OleDbConnection conForum;
            OleDbCommand cmdRead;
            OleDbDataReader dtrRead;
            conForum = new OleDbConnection(@"PROVIDER=Microsoft.Jet.OLEDB.4.0 ;DATA Source=myForum\db\FORUM.mdb");
            cmdRead = new OleDbCommand("SELECT UserName,PostsCount FROM Users",conForum);
            conForum.Open();
            dtrRead = cmdRead.ExecuteReader();

            while(dtrRead.Read())
            {
                lblName.Text = "<LI type=1>" + dtrRead["UserName"] + "</LI>";
                lblPostCount.Text = dtrRead["PostsCount"] + "<BR>";
            }
            dtrRead.Close();
            conForum.Close();


            }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.btnForum.Click += new System.EventHandler(this.btnForum_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void btnForum_Click(object sender, System.EventArgs e)
        {
            Response.Redirect(@"myForum\Default.aspx");
        }

    }
}
---------------------------------------------------------------------
Here is the source code. I am unable to display the file at label. Is it the problem of path?(I am not sure).

Any help would appreciated.



Goh Hoang Yuh
- C# Beginner in ASP.NET
 
Old November 9th, 2005, 04:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Did you test to see if the problem is that no records are being returned? Is the page loading ok, just nothing being assigned to the label? Also, I think when piecing the fields to the string, you need the ToString(): dr["field"].ToString() to get the string. And, for the label, you have to do +=, not =:
lblName.Text += dr["field"].ToString()

The last value currently overwrites all the text, which the last field could be blank and that is why you are having a problem.

Brian
 
Old November 9th, 2005, 08:38 PM
Authorized User
 
Join Date: Oct 2005
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to richie86
Default

Oh thanks, but at last i recover that the main problem is the code
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false" Inherits="HoangYuh._Default" %>
is missing on my Default.aspx, i think this is the main problem to make all my database read nothing and button doesn't redirect.
Thanks anyway.

Goh Hoang Yuh
- C# Beginner in ASP.NET
 
Old November 10th, 2005, 01:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

That would be a problem, yes.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Show Foxpro Database in ASP Slayer_CauTioN Classic ASP Databases 1 July 20th, 2008 07:28 PM
Show result during SQL statement rtr1900 ASP.NET 2.0 Basics 0 December 7th, 2006 06:51 AM
Very beginner - Result didn't show in the browser not24 ASP.NET 1.0 and 1.1 Basics 7 February 22nd, 2005 12:08 PM
Show result from query akibaMaila VB.NET 2002/2003 Basics 2 January 18th, 2005 12:43 PM
problem in show result (vb.net) q8z Beginning VB 6 0 October 27th, 2004 03:01 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.