A little experience to finish a small website (1): ASP.net with Access database

Source: Internet
Author: User
Tags connect access database root directory
access|asp.net| Data | Database

The first time with others to do things, their own little experience, write down, although compared to vegetables, but still have to do some records, if there are errors, please enlighten me, thank you:
Used to make things with ASP.net and sqlServer2000, this time with access, although it is the first time used, but the feeling and the use of sqlServer2000 is not very different, the following to compare the use of the two:
SqlServer2000:
1> namespace using System.Data;
Using System.Data.SqlDb;
2> connection statements are recorded in the previous essay, which is no longer recorded here.

Main record access usage:
1> namespaces: Using System.Data;
Using System.Data.OleDb;

   2> Connection statement:
              String constring= "Provider=Microsoft.Jet.OLEDB.4.0; Data source= ";
             Constring+=server.mappath (@ "\jlgps \db\jlgps.mdb ");
     //The above statement, "@" represents an absolute string, which means "\" In this does not need "\" to represent the
     the first "\" Indicates that the directory "Jlgps" is found from the root directory (such as C:\Inetpub\wwwroot), and if no "\"
     means to find it from the current application directory (JLGPS), then this will be written as @ "DB \jlgps.mdb.
      recommended the latter, the former may be an absolute path, the latter is a relative path, a less likely error.
             OleDbConnection con=new OleDbConnection (constring);
              con. Open ();//This completes the database connection.

  3> Command object:
              The approximate usage is the same as SQL Server, except that the name changes somewhat:
             SQL Server is preceded by a SqlCommand cmd=new SqlCommand ();
             and Access's all start with OLE DB, such as: OleDbCommand, OleDbDataReader ..... , and so on

  4> Issues involving user names and passwords for Access databases:
              Start my access's MDB file does not have a username and password set, and the above connection statement can be used to
          connect successfully. Then I thought for a bit more secure, I want to set the open password for the database MDB file, in
        I will open the MDB file in the "Tools",-"security"-"Set the database password" The password is set in, but
after         will not be connected to the database, I tried to add in the connection statement similar to SQL Server in the UID,PWD, etc.,
         but did not succeed, finally after a few attempts to find a solution to the problem:
        Instead of setting the password in Tools, security-set database password, you can set the password in Tools, security-
         user and group accounts , so that when you open the MDB file to enter the password
        , and the database connection statement is original, do not make any changes to connect the database.

5>access field type problem, Access's field type is difficult to match the type of OleDbType one by one,
Then take the similar, like the memo type in Access, then use the OleDbType
LongVarChar can be. Like what:
OleDbParameter para=new OleDbParameter ("@proFun", Oledbtype.longvarchar);
Para. value=myaddpro.profun;//The function description parameter of a Product object, remark type
Cmd. Parameters.Add (para);







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.