Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
hi every one we have not access to enter fir record to user but when we login admin account that same prevent to enter record to admin ...i wish admin enter record
access.cs code below
C#
namespace Crime_System
{
    class access
    {
        public bool fread()
        {
            Hashtable ht = new Hashtable();
            FileStream sfs = new FileStream("temp.xml", FileMode.Open, FileAccess.Read);
            Hashtable h = new Hashtable();
            BinaryFormatter formatter = new BinaryFormatter();
            h = (Hashtable)formatter.Deserialize(sfs);
            string status = Convert.ToString(h["name"]);
            sfs.Close();
            if (status == "Admin" || status == "admin")
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}


form code below

C#
private void button1_Click(object sender, EventArgs e)
       {
           access validate = new access();
           MSG message = new MSG();
           if (validate.fread() == true)
           {

               firsave();
           }
           else
           {
               message.Get_MSG_ERR("Sorry,Access is not gurantted");

           }
       }


plz help me any body..
Posted
Comments
Aniket Yadav 25-Feb-12 6:46am    
what is your question. elaborate little more

C#
Hashtable ht = new Hashtable(); //What's this code for? It seems unnecessary here.
FileStream sfs = new FileStream("temp.xml", FileMode.Open, FileAccess.Read);
Hashtable h = new Hashtable();
BinaryFormatter formatter = new BinaryFormatter();
h = (Hashtable)formatter.Deserialize(sfs);
string status = Convert.ToString(h["name"]);//status will never be "Admin" or "admin". Check your file.  
sfs.Close();
if (status == "Admin" || status == "admin") //if (status.ToUpper() == "ADMIN")
{
    return true;
}
else
{
    return false;
}



and Better suggestion:

C#
FileStream sfs = new FileStream("temp.xml", FileMode.Open, FileAccess.Read);
Hashtable h = new Hashtable();
BinaryFormatter formatter = new BinaryFormatter();
h = (Hashtable)formatter.Deserialize(sfs);
string status = Convert.ToString(h["name"]);
sfs.Close();
return (status.ToUpper() == "ADMIN")? true:false
 
Share this answer
 
My above code do not work correctely when we login as admin username password
then they stop me for insert record...plz help me
 
Share this answer
 
Comments
André Kraak 26-Feb-12 10:17am    
If you have a question about or comment on a given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.

Please move the content of this solution to the solution you are commenting on and remove the solution.
Thank you.

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