unable to connect to Access DataBase

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ezhar
    New Member
    • Aug 2010
    • 13

    #1

    unable to connect to Access DataBase

    Code:
    try
            {
                OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\ikcit.mdb");
                OleDbDataAdapter da = new OleDbDataAdapter();
                da.InsertCommand = new OleDbCommand("Insert into student values(@name,@address,@spno,@smail,@domain,@course)", con);
                da.InsertCommand.Parameters.Add("@name", OleDbType.VarChar).Value = TextBox1.Text;
                da.InsertCommand.Parameters.Add("@address", OleDbType.VarChar).Value = TextBox2.Text;
                da.InsertCommand.Parameters.Add("@spno", OleDbType.Numeric ).Value = TextBox3.Text;
                da.InsertCommand.Parameters.Add("@smail", OleDbType.VarChar).Value = TextBox4.Text;
                da.InsertCommand.Parameters.Add("@domain", OleDbType.VarChar).Value = DropDownList1.Text ;
                da.InsertCommand.Parameters.Add("@course", OleDbType.VarChar).Value = DropDownList2.Text ;
                con.Open();
                da.InsertCommand.ExecuteNonQuery();
                con.Close();
      
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
    When I am trying to insert some data I am getting error.


    Could not find file 'C:\WINDOWS\sys tem32\ikcit.mdb '.

    Unable to understand Why??
    Thanx in advance
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Change your Connection String so that Data Source is pointing to the path where the ikcit.mdb file is located.

    -Frinny

    Comment

    • ezhar
      New Member
      • Aug 2010
      • 13

      #3
      Is it not possible to add virtual path rather then physical path?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I don't know...
        Sorry.


        -Frinny

        Comment

        • pod
          Contributor
          • Sep 2007
          • 298

          #5
          you could setup your path in the project properties under the Settings tab, and call for it by name:
          Code:
          OLEconn.ConnectionString = My.Settings.MyDatabase
          Project->Properties->Settings->ConnectionStri ng :


          ..but you would still have to provide either a relative or absolute path to your database... I think it is better practice to use an absolute path ...although, if you do not wish, try removing the double backslash from your path
          Code:
          "Data Source=ikcit.mdb"
          Last edited by pod; Sep 30 '10, 01:34 PM. Reason: clarification

          Comment

          • ezhar
            New Member
            • Aug 2010
            • 13

            #6
            Thanx for the reply
            but i got the answer and it is bit simple

            Comment

            Working...