Tag Archives: howto

Add records to SQL DB using command builder and dataset in C#

When I talk about C# Dataset quote that it can also be used for insertion of data into the table too. In this post, we are going to learn how to.


  1. Data connection with SQL
  2. Dataset
  3. Command builder object

In our example, we had MiniPurchaseInfo table and dataset associated with it.  First thing first, the dataset

SqlDataAdapter MiniPurchaseInfo = new SqlDataAdapter("select * from minipurchaseinfo", con);
 MiniPurchaseInfoDataSet = new DataSet();
 MiniPurchaseInfo.Fill(MiniPurchaseInfoDataSet, "minipurchaseinfo");

We simply make the query, filling the information to the dataset and so on. The next step is to create a row with the DataRow object and add the data row to our dataSet object.

DataRow dro;

dro = MiniPurchaseInfoDataSet.Tables[0].NewRow();
 dro["entryno"] = entryNo;
 dro["supinvoice"] = txt_invoice.Text.ToString();
 dro["supid"] = SUPID;
 dro["netamount"] = net;

add the row to the dataset.


The final step is to set up the command build which has the capability of insertion and deletion operations with DB adapter and dataset.

System.Data.SqlClient.SqlCommandBuildercmdbuilder = new System.Data.SqlClient.SqlCommandBuilder(MiniPurchaseInfo);

Set insert command of the adapter from the command builder object

MiniPurchaseInfo.InsertCommand = cmdbuilder.GetInsertCommand();

Call the update command of the adapter which will update the new row stored in the dataset into the database table.

int r = MiniPurchaseInfo.Update(MiniPurchaseInfoDataSet.Tables[0]);

The update will return a none zero value when the insertion performed.

Insert if not exist sqllite [android]

We are femiliar with if not exits keyword when working sqllite database in Android or in web applications as well.

If not exist work with create statements, so how do we implement the same tactics in insert statement ?

Here what I found ,

Take a look at what we have

Here I got a table Entries which keep track of different entries with auto grnerated eid column. I wanna make happends only insert entries that is not exist in the table.entries.pngTodo

  1. Create a unique index on ename column
  2. usere insert or ignore into statement instead of insert into
Index the colum
create unique index Entry_name_start on Entries ( ename ) ;

This will generate a intex on column ename, which means it can’t be duplicated

The new insert insert.png
insert or ignore into "Entries" (
values (

It will work….

Note: I used Android Studio and plugin called DB Browser in this tutorial

How to configure Nox Emulator for Android Studio

Nox Player is one of the coolest Android Emulater for playing Android Games as well as for Application Developement and Testing.  You can use the Emulator to run app you are developing with Android Studio.2018-08-30_222153

  1. Download the Nox Player from the web and Install the software.[Make sure that you had installed graphics driver properly, otherwise the installation may fail].
  2. Start Nox Player, you can switch between Tablet to Mobile view by changing Advanced Settings in Nox.
  3. Let’s Turn on Developer Option by Clicking 3 or four times in Build number  [About Phone in Nox]
  4. Also Turn on USB Debugging [Developer Option]
  5. Final step is to run the adb command with ip address in command prompt. [adb resides in Nox’s bin folder]

adb  command [ run on command prompt]

nox_adb.exe connect

Optionaly you can create and run a batch file wich can be used to run Nox adb  with a single click. Please make sure your batch file resides in the same bin folder where Nox player file found.[Use right click Nox Player short Cut to find the location in Windows].

You can download the batch file from Github and move to the bin folder

  • Now Start the Android Studio
  • Also start the Noxplayer and Turn on Developer option
  • Run the adb
  • Try debug App in Adroid Studio and it will be start appearing in the device list, otherwise run the adb with Run as admin a and  try again


How to create a DataView in C#

DataView is special table view which allows you to traverse through rows and columns respectively. C# DataView is an offline data holder as DataSet.

What you need is

  1. A Database connection object
  2. A Data Adapter which configures the data table using SQL query.
  3. And a dataset which holds the table information.

Create a data view object and initialize it with the dataset tables name as follows

SqlDataAdapter AccountRegistration = new SqlDataAdapter(“select * from accountregistration order by grpid”, Common.con);

DataSet AccountRegistrationDataset=new DataSet();
DataView AccountRegistrationTableView = new DataView(AccountRegistrationDataset.Tables[0]);

Learn about more DatView operations


How to use dataView rowfilter for searching rows in C#.Net

You can simply use SQL query statements to retrieve desired data from database server with C# and ADO.Net. But there are plenty of ways to search your localized version of data which is stored in dataSet and dataView.

We already learn how to use Find and Findrow methods for searching data in Visual Studio App. This post will show how to use row filter property of  DataView for sorting data rows.

  1. First up all you need to create Data adaptor, dataSet, and dataView.
  2. In our example, I have a date field in the database table, so that I can filter for specific date ranges as follows
 Common.AccountReportDV.RowFilter = "invoicedate>='" + dateTimePicker1.Value.ToShortDateString() + "' and invoicedate<='" + dateTimePicker2.Value.ToShortDateString() + "'";

Here common is a public static class where kept the Database functions. The above statement will be looking for data between the two dates.

You have to use Common.AccountReportDV and not Common.AccountReportDV.Table.rows  for retrieving the result as follows.

foreach (DataRowView row in Common.AccountReportDV)

console.WriteLine(row["<column name here>"]);


DataRowView is a special class which helps to access data rows in a DataView object.

Remove OEM Recovery Drive letter in Windows 10

Branded PC like HP/Lenovo used to set recovery partition[Windows 10/7], probably with drive letter D/E/F etc. Sometimes there are applications which always work with specific drives. In such cases when you try to change OEM partition, the effort may fail.

 OEM partition is designed for system recovery or factory restore. It allows users to easily and quickly restore the system to the original state when system failure or system crash occurs

I personally suggest removing the drive letter from the OEM part, this becomes another troublesome job indeed. With DiskPart command you can remove drive letter of volumes.


Enter cmd command(Window + R) and Run button

Type diskpart on your command prompt

Type List Volume

Choose the OEM voliume with select Volume [volume#]

Execute Remove letter [Drive Letter]

If you are too lucky the OEM drive will disappear from My computer/My Pc. and the drive letter is available for use.