Posts

Showing posts with the label database

How to reset Autonumber column from 1 after delete all table data in MS Access?

Image
MS Access is basic and stander database for developers.essay to use and work. Normally like work in excel.now we discuss for our topic "How to reset Autonumber column from 1 after delete all table data in MS Access?". Some time developers work on db and after deployment time need to reset or blank database for user use.no testing data in it.so developers need to reset identity ( Primary,Autonumber  ) column.for that need to query on db for reset to 1 or want to any numbers. "ALTER TABLE # yourTable # ALTER COLUMN # column-name # COUNTER(1,1)" Execute this query with edit your table name and column name. You can also set gaps in increment and set start of numbers.like want to start from 1001 and gap with 10 then this is possible to do in. Related Post How to get html of web page in string by web page url. Export datatable data in Excel Fill datatable from access database CRUD Operations in win form application with access database

Export datatable data in Excel

Hi to all. Normally we work in database but some time we need reporting or get data in soft copy to send email or for record purpose. So we export data in excel file.hear i show you how to export data from datatable . first get data from database to in datatable which we show in starting session. I genrate one function that help to export in Excel .   public bool DatatabletoExcel(DataTable Dt)         {             bool result = false;             try             {                 //create dialog for create file                 SaveFileDialog sfd = new SaveFileDialog();                 sfd.FileName = "File Name";                 sfd.DefaultExt = "xls";                ...

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";             ...

Fill List view from database

Image
Hi to all. In this post we make code for populate list view from database. first we take one list view and name them listdata. and set in form with require height and width. listview now make one function FillList() to populate listview.         private void FillList()         {             try             {                 //use dbhelper class to fill datatable from database.                 DbHelper Db = new DbHelper();                 //make query string .                 string sQry = "Select * from Employee";                 //call function for fill datatable.                 DataTable Dt = Db.FillDataTable(sQry);     ...

Fill datatable from access database

Hi to all. In previous post we show  how to execute query in database. now in this post we see how to get data from database. and fill in  DataTable . for this we create on function in dbhelper class which we use in previous example.         public DataTable FillDataTable(string sQry)         {             try             {                 DataTable Dt = new DataTable();                              //Check db connection                 if (dbConnection.State != ConnectionState.Open)                 {                     dbConnection.Open();                 }         ...

CRUD Operations in win form application with access database

Hi to all, In first post we connect with access database now in this post we make operations in database. First we create one method that help to execute sql query in database. public bool Executquary (string sQuary)         {             try             { //check connection                 if (dbConnection.State != ConnectionState.Open)                 {                     dbConnection.Open();                 } //create command                 OleDbCommand cmd = new OleDbCommand(sQuary);                 cmd.Connection = dbConnection;                 try                 { /...

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...