Click here to Skip to main content
16,004,602 members
Please Sign up or sign in to vote.
1.50/5 (4 votes)
See more:
Class clsDataBase.cs
C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
namespace dapbs
{
    public class clsDatabase
    {
        internal static System.Data.Common.DbProviderFactory DbProviderFactory;
        internal static System.Data.Common.DbConnection DbConnection;
        internal static System.Data.Common.DbTransaction DbTransaction;
        public static bool MoData()
        {
            DbProviderFactory = System.Data.SqlClient.SqlClientFactory.Instance;
            DbConnectionStringBuilder DbConnectionStringBuilder = DbProviderFactory.CreateConnectionStringBuilder();
            DbConnectionStringBuilder.Add("Data Source", "(local)");
            DbConnectionStringBuilder.Add("User ID", "sa");
            DbConnectionStringBuilder.Add("Password", "sa");
            DbConnectionStringBuilder.Add("Initial Catalog", "dapan");
            bool IsConnected;
            try
            {
                DbConnection = DbProviderFactory.CreateConnection();
                DbConnection.ConnectionString = DbConnectionStringBuilder.ConnectionString;
                DbConnection.Open();
                IsConnected = true;
            }
            catch
            {
                IsConnected = false;
            }
            return IsConnected;
        }
    }
}



Class Student.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace dapbs
{
    public class colStudent:System.ComponentModel.BindingList<entStudent>
    {
        public colStudent()
        {
            Fetch();
        }
        
        public static colStudent Get()
        {
            return new colStudent();
        }

        private void Fetch()
        {
            RaiseListChangedEvents = false;
            System.Data.Common.DbDataReader SelectDataReader = entStudent.Select();
            while (SelectDataReader.Read())
            {
                entStudent ent = entStudent.Get(SelectDataReader);
                this.Add(ent);
            }
            SelectDataReader.Close();
            RaiseListChangedEvents = true;
        }       
    }
}

Class entStudent.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using dapbs;
namespace dapbs
{
    public class entStudent
    {
        //
        public System.Collections.Specialized.NameValueCollection _PropErrors = new System.Collections.Specialized.NameValueCollection();
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string PropertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(null, new System.ComponentModel.PropertyChangedEventArgs(PropertyName));
        }
        private bool _IsNew;
        public bool IsNew
        {
            get { return _IsNew; }
            set { _IsNew = value; }
        }
        private bool _IsDirty;
        public bool IsDirty
        {
            get { return _IsDirty; }
            set { _IsDirty = value; }
        }
        public bool IsValid
        {
            get { return _PropErrors.Count == 0; }
        }
        public bool IsSavable
        {
            get { return IsDirty && IsValid; }
        }
        public void MarkOld()
        {
            _IsDirty = false;
            _IsNew = false;
        }
        public string Error
        {
            get
            {
                string Result = string.Empty;
                if (_PropErrors.Count > 0)
                    Result = _PropErrors[0];

                return Result;
            }
        }
        //Attribute
        private string _IDStudent;
        private string _StudentName;

        public string IDStudent
        {
            get { return _IDStudent; }
            set
            {
                if (_IDStudent != value)
                {
                    _IDStudent = value;
                    IsDirty = true;
                    OnPropertyChanged("IDStudent");
                }
            }
        }
        public string StudentName
        {
            get { return _StudentName; }
            set
            {
                if (_StudentName != value)
                {
                    _StudentName = value;
                    IsDirty = true;
                    OnPropertyChanged("StudentName");
                }
            }
        }
       
        //Constructors
        protected entStudent()
        {
            IsNew = true;
        }
        protected entStudent(System.Data.Common.DbDataReader DataReader)
        {
            Fetch(DataReader);
            IsNew = false;
        }
        //Methods
        public static entStudent New()
        {
            return new entStudent();
        }
        public static entStudent Get(System.Data.Common.DbDataReader DataReader)
        {
            return new entStudent(DataReader);
        }
        protected void Fetch(System.Data.Common.DbDataReader DataReader)
        {
            _IDStudent = DataReader.GetString(DataReader.GetOrdinal("IDStudent"));
            _StudentName = DataReader.GetString(DataReader.GetOrdinal("StudentName"));
           
        }       
     
        public List<entStudent> getAllCategory()
        {
            // Please help me code
        }   

Class Interface
XML
<asp:DataList ID="dlStudent" runat="server" RepeatDirection="Horizontal"
                    Width="100%">
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink2" runat="server"
                            Text='<%# Eval("StudentName") %>'></asp:HyperLink>
                    </ItemTemplate>
                </asp:DataList>

Call event for DataList
protected void Page_Load(object sender, EventArgs e)
{
    // Please help me code
}
Posted
Updated 28-Apr-11 16:07pm
v2
Comments
walterhevedeich 28-Apr-11 22:05pm    
And what is the problem?
sawyer8x 29-Apr-11 0:03am    
I want write method getallstudent() and view for datalist
thanks!
Ankur\m/ 29-Apr-11 0:23am    
Add that in your question by selecting 'Improve Question'.
And remove the code dump. Paste only the relevant code here.
walterhevedeich 29-Apr-11 0:29am    
You want to write it? Then go ahead and write the method and post the issues you face. You'll get a lot of help if you do it this way, rather than asking people to write code for you.
Wonde Tadesse 28-Apr-11 22:14pm    
Can you specify the problem ?

1 solution

Here is some pseudo code I put together for you. Obviously it is unfinished so you'll need to fill in the blanks.

C#
public void GetAllStudents()
{
    var bar = from all in entity.StudentBar
              select all;

    foreach (Student student in bar)
    {
        if (student.dumb)
        {
            AskTutorForHelp();
        }
        else
        {
            FigureItOutForYourself();
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900