943,769 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 619
  • ASP.NET RSS
Feb 16th, 2009
0

i need help in code of connecting from asp.net 2005 to access

Expand Post »
i want to connect asp.net 2005 with access .
now i need for the code do do this connection
Similar Threads
Reputation Points: 7
Solved Threads: 0
Newbie Poster
nada fouad is offline Offline
6 posts
since May 2008
Feb 16th, 2009
0

Try This

Create a variable Like x
Then
x="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\office.mdb"
Note :C:\Program Files\office.mdb By replacing it put your datasource And then try this
Reputation Points: 10
Solved Threads: 2
Light Poster
manoj_582033 is offline Offline
39 posts
since Nov 2008
Feb 17th, 2009
0

Re: i need help in code of connecting from asp.net 2005 to access

thnx for reply

what about the full code & the veriables when i want to do insert and the code to execute the query ???
Reputation Points: 7
Solved Threads: 0
Newbie Poster
nada fouad is offline Offline
6 posts
since May 2008
Feb 17th, 2009
0

Re: i need help in code of connecting from asp.net 2005 to access

Go to http://www.connectionstrings.com
It is your friend. Bookmark it.
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
Feb 17th, 2009
0

Re: i need help in code of connecting from asp.net 2005 to access

There are two functions for generating the conn string depending on the version of access, which can be determined by the file extension or various other ways.

c# Syntax (Toggle Plain Text)
  1. public static string BuildAccessConnectionString(string Filename, string Username, string Password, string DatabasePassword)
  2. {
  3. return string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='{0}';User Id={1};Password={2};Jet OLEDB:Database Password={3};",
  4. Filename.Replace("'", "''"),
  5. Username,
  6. Password,
  7. DatabasePassword);
  8. }
  9. public static string BuildAccess2007ConnectionString(string Filename, string DatabasePassword)
  10. {
  11. return string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='{0}';Persist Security Info=False;Jet OLEDB:Database Password={1};",
  12. Filename.Replace("'", "''"),
  13. DatabasePassword);
  14. }
  15. private void simpleButton3_Click(object sender, EventArgs e)
  16. {
  17. string connStr = BuildAccessConnectionString(@"C:\data\CustList01.mdb", string.Empty, string.Empty, string.Empty);
  18. DataTable result = new DataTable();
  19. using (OleDbConnection conn = new OleDbConnection(connStr))
  20. {
  21. conn.Open();
  22. using (OleDbCommand cmd = new OleDbCommand(@"Select * From [CustList01]", conn))
  23. {
  24. using (OleDbDataReader dr = cmd.ExecuteReader())
  25. {
  26. result.Load(dr);
  27. }
  28. }
  29. conn.Close();
  30. }
  31. //Work with table
  32. MessageBox.Show(result.Rows.Count.ToString());
  33. }
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: not sure of codes
Next Thread in ASP.NET Forum Timeline: How to deploy SharePoint website or webapplication?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC