Click here to Skip to main content
15,915,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How to Retrive username nd password from Microsoft Access 2007 to C#.net.

Regards
Balamurugan
Posted
Comments
Zoltán Zörgő 3-Jan-13 6:59am    
What username, what password? Stored in a table, or the one of "user level security"?
Balamurugan1989 3-Jan-13 7:02am    
It has been stored in a table.Table name is User from this table i should retrive...

Supposing you need only the proper connection string syntax, look around here: http://www.connectionstrings.com/access-2007[^].

Start with this short tutorial: http://www.dscripts.net/2009/01/20/connect-to-microsoft-access-mdb-database-using-csharp/

Here is a screencast in this topic: http://www.youtube.com/watch?v=uw9vVvgqVMk[^]
 
Share this answer
 
C#
private void button1_Click(object sender, EventArgs e)
{
login();
}
public void login()
{
string file_name;
file_name = Application.StartupPath + "\\" + "username.txt";
System.IO.StreamWriter objwriter;
objwriter = new System.IO.StreamWriter(file_name);
objwriter.WriteLine(textBox1.Text);
objwriter.Close();
string nam;
WeightBridge.Class1 obj = new WeightBridge.Class1();
nam = obj.get();
nam = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\weightbridge.accdb;Persist Security Info=False;";
OleDbConnection con = new OleDbConnection(nam);
con.Open();
OleDbCommand cmd = new OleDbCommand("SELECT UserName,pwd FROM [User] WHERE UserName='" + textBox1.Text + "' AND pwd='" + textBox2.Text + "'", con);
OleDbDataReader dr = cmd.ExecuteReader();
string userText = textBox1.Text;
string passText = textBox2.Text;
while (dr.Read())
{
if ((dr["UserName"].ToString() == userText) && (dr["pwd"].ToString() == passText))
{
this.Hide();
MasterPage mp = new MasterPage();
mp.Show();
this.Hide();
}
else
{
MessageBox.Show("Invalid UserName/Password");
}
}
dr.Close();
con.Close();
}
 
Share this answer
 
v2
Comments
fjdiewornncalwe 21-Feb-13 16:47pm    
My 1: SQL Injection Nightmare.

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