Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
See more:
ASP.NET
Hello Developers!!!!
I want to build a ASP.NET website by using a MS ACCESS database and C# Language.I have
searched a lot but i can't find write answer.
Whenever i try to find connectivity solution, The code that i found on Google search is Like
<pre>
using System.Data.Oledb;
__________________________________
Hide Copy Code
namespace consample
{
pubic class OledbConnection
{
public void Perform()
{
OledbConnection con= new
OledbCOnnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\mydatabase.mdb")//Data provider for MS ACCESS
con.Open();
OLEDBCommand cmd=new OLEDBCOmman();
cmd.Connection=con;
cmd.CommandType=CommandType.Text;
cmd.CommandText="Select * from emp";
OledbDataReader dr= new OledbDataReader();
dr=cmd.Executereader();
while (dr.Read()==true)
{
/// Do some coding here
}
}
}
}
__________________________________________
I am totally confused that why they only give local host or C:\ path if we want to upload our site
1 solution
Solution 1
You can use Server.MapPath() to locate the access file in connectionString so that it searches in
deployed location where application resides. Here main purpose is at runtime application should
be able to locate the access data file.
code snnipet:
Hide Copy Code
OledbConnection con= new
OledbCOnnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source="+Server.MapPath("mydatabase.mdb")+";";
I have a hosted website, and I need to add a database with password and log-in information. (MS
Access DB), I tried a lot but can't connect with it (on local machine it works). I tried to change
connection string but it still doesn't work. Database is in folder App_Data. Here's what I type in
Login.aspx page:
This does not work. What do I need to change? I've put my web site on somee.com
c# asp.net ms-access
shareimprove this question
edited May 14 '13 at 13:18
Mark Schultheiss
25.7k88 gold badges5757 silver badges8585 bronze badges
asked May 14 '13 at 13:09
user2362291
1222 gold badges33 silver badges77 bronze badges
Why are you not using the included SQL Express database? – Jake1164 May 14 '13 at
13:14
It's a task for education.... – user2362291 May 14 '13 at 13:15
Is the "program" Access installed on the server? Also, I cringe whenever I see someone
using Access with a website. Please don't do it. – CM Kanode May 14 '13 at 13:15
Yes it's intalled – user2362291 May 14 '13 at 13:16
somee.com/DOKA/DoHelpTopics.aspx?docode=false&thnid=91 they have this but I
don't understand where I should write it – user2362291 May 14 '13 at 13:18
1 Answer
active oldest votes
3
Did you check the help page on SOMEE for connecting to an access database?
OleDbCommand cmd =
new OleDbCommand("Select * FROM Table1", conn);
reader = cmd.ExecuteReader();
datagrid.DataSource = reader;
datagrid.DataBind();
}
// catch (Exception e)
// {
// Response.Write(e.Message);
// Response.End();
// }
finally
{
if (reader != null) reader.Close();
if (conn != null) conn.Close();
}
shareimprove this answer
edited May 14 '13 at 13:45
answered May 14 '13 at 13:18
Jake1164
10.2k66 gold badges3838 silver badges5858 bronze badges
I saw this. but everything VS sayes that & can't be used in string and all is read
– user2362291 May 14 '13 at 13:20
What does that mean? What cant be used in a string? All what is read? – Jake1164 May
14 '13 at 13:23
I tried to change con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=" + Server.MapPath("~\\App_Data\\WebSiteDatabase.accdb"); to
"PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" &
Server.MapPath("App_Data\WebSiteDatabase.accdb") and it shows errors
– user2362291 May 14 '13 at 13:25
Md Sarfaraj
Feb 13 2019
12.7k
0
3
This blog demonstrates how to create a Login page in ASP.NET with MS Access database using
C# language.
facebook
twitter
linkedIn
Reddit
o Email
o Bookmark
o
o
o
expand
In this blog, let us see how to create a login page using C# language in an ASP.NET application
that is using MS Access database. Please follow the below steps.
STEP 1
STEP 2
login.aspx
1. <body>
2. <form id="form1" runat="server">
3. <div>
4.
5. <asp:Label ID="Label1" runat="server" Text="Username"></asp:Label>
6. <asp:TextBox ID="TextBox1" runat="server" Width="146px"></asp:TextBox>
7. <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
8. ControlToValidate="TextBox1" ErrorMessage="Enter username." ForeColor="R
ed"></asp:RequiredFieldValidator>
9. <br />
10. Password<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"
11. Width="147px"></asp:TextBox>
12. <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
13. ControlToValidate="TextBox2" ErrorMessage="Enter password." ForeColor="R
ed"></asp:RequiredFieldValidator>
14. <br />
15. <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Log In"
/>
16. <br />
17. <asp:Label ID="Label2" runat="server"></asp:Label>
18. </div>
19. </form>
20. </body>
After inserting the code, you will get a UI like in the below image.
Default.aspx
1. <body>
2. <form id="form1" runat="server">
3. <div>
4.
5. <asp:Label ID="Label1" runat="server" Text="Welcome"></asp:Label>
6.
7. </div>
8. </form>
9. </body>
STEP 3
Now, let's create our Access database. Here are the details -
Note - Do not forget to create the database (LogInDatabase.mdb) under your project folder.
STEP 4
After creating the database, let us come back to our Visual Studio project. Double-click the "Log
In" button and add the below code.
login.aspx.cs
1. using System.Data;
2. using System.Data.OleDb;
STEP 5
In this blog, I covered the creation of the Login page in ASP.NET with Access database. If you
face a problem with this code, please comment below.