Posts

Showing posts with the label execute

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

Insert date in database by DateTimePicker

Hi to all. If you are new in developing so you have mostly problem to add date in database. so i make code for new beginners. first take one  DateTimePicker name it to Dtdate. Set property Format=Short so we get simple date not in long format. Take one button so on click event we save in database. In Button click event. string Dtdate = Dtdate.Value.ToString("yyyy-MM-dd"); Now the string contain date string in "yyyy-MM-dd" format. on save time make query for date. string sQuary="Insert into testTable (Dtdate) Values (#"+Dtdate +"#)" ; Execute this query. In query I use "#" on start and end. that specify this is date. in database date save always in  "yyyy-MM-dd" format so i convert in this format. Thanks for read this post

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