Posts

Showing posts with the label access

Insert data in AutoNumber DataType (Access Database).

Hi to all. Normally we insert data in table.but when we need some unique identity we use primary key and make  AutoNumber datatype in access database. so when we insert data in database not add column in query of insert. Like table name is Test and columns are Id=>AutoNumber,Name=>Text Query for insert is ="Insert into Test (Name) Values ('TestName')" Hear we not mention Id because Id is AutoNumber. It automatically set last id increment 1.and if we want the inserted id in database after insert query make one code " Select @@Identity "; to execute.         public int InsertData(string sQuary)         {             try             {                 //for get last inserted id                 string sQryIdentity = "Select @@Identity";             ...

Create class for Access database connection

Image
Hello to all,      Here we make on class that help to connect application's database by simply call class.          First we create Win form application .like Testapp. create one Access database like Testapp.accdb. after that we open application in visual studio and create one folder that name app_code. in this folder add one class file.and name them dbhelper.cs. public class DbHelper     {         public static OleDbConnection dbConnection;         public DbHelper()         {             dbConnection = new OleDbConnection("Provider=Microsoft.Ace.OLEDB.12.0; Persist Security Info = False; Data Source=c:\\Testapp.accdb");             dbConnection.Open();         } } For this code you need to include some libraries like System.Data.OleDb ; Now time to use this c...