We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,849 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Asp.net simple data connection

Ok so I have made ASP.NET website I have used Access database 2010 but I am having problems with one particular thing when I try and run the website I am getting this error which says OleDbException was unhandled by user code and Could not find file 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\CitiesDatabase.accdb'. The error points at
myTable = new DataTable();
dataAdapter.Fill(myTable);

Here is my code:

Code blocks are created by indenting at least 4 spaces
... and can span multiple lines

public partial class NavigateDatabase : System.Web.UI.Page
{

DataTable myTable;

OleDbDataAdapter dataAdapter;
 int rowIndex;
protected void Page_Load(object sender, EventArgs e)
{

    string connStr;
    string sqlStr;

    connStr = "PROVIDER = Microsoft.jet.OLEDB.4.0;" +
              "Data Source = tblCities.mdb";


    sqlStr = "SELECT * FROM FootballResults";
    dataAdapter = new OleDbDataAdapter(sqlStr, connStr);


    myTable = new DataTable();
    dataAdapter.Fill(myTable);
}

public void upDateTextBoxes(int row)
{
    txtCity.Text =
    myTable.Rows[row]["Team"].ToString();
    txtCountry.Text =
    myTable.Rows[row]["Player"].ToString();
    Session.Add("RowIndex", row);
}
protected void button1_Click(object sender,
     EventArgs e)
{
    rowIndex = 0;
    upDateTextBoxes(rowIndex);

}

protected void button2_Click(object sender, 
  EventArgs e)
{

    rowIndex = Convert.ToInt16( Session["RowIndex"]);

    if(rowIndex<((myTable.Rows.Count) -1))
    {
        rowIndex++;
        upDateTextBoxes(rowIndex);
    }

}

protected void button3_Click(object sender,
   EventArgs e)
{
    rowIndex = Convert.ToInt16( Session["RowIndex"]);

    if (rowIndex > 0)
    {
        rowIndex--;
        upDateTextBoxes(rowIndex);
    }


}

protected void button4_Click(object sender, 
   EventArgs e)
{
    rowIndex = myTable.Rows.Count - 1;
    upDateTextBoxes(rowIndex);
}

}

2
Contributors
1
Reply
6 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
Muni123
Newbie Poster
5 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

So... my first question is... is this website hosted on a domain somewhere or is it hosted on your local computer?

The reason I ask this is because your connection string seems to be pointing at an access database on a local drive as such:
C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\CitiesDatabase.accdb

So... if it's hosted online one might want to double-check the connection string to ensure it's properly pointing to the .accdb file location. One may also want to make sure that the perms on that file are set correctly in such a way that the code can actually reach the file (i.e.: readable/writable).

It's somewhat difficult to tell as the code you provided doesn't seem to fully encompass the connection string other than to reference a connection type and a .mdb file and doesn't indicate anywhere within where it would be referencing CitiesDatabase.accdb.

My thought is that, if it's not related to the code above... you may have data connections hard coded into the front end of your page in datatables or dropdowns or the likes which are pointing at local files instead of site resources.

Lusiphur
Posting Shark
Team Colleague
966 posts since Jun 2010
Reputation Points: 207
Solved Threads: 127
Skill Endorsements: 2

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0567 seconds using 2.69MB