Author Archives: salviashish

Updating database using dataset

This topic illustrates how to update data in a database using a DataSet. It is important to remember that you can also insert, update, and delete data in a database directly using a SqlCommand.

Once the DataSet is loaded, you can modify the data, and the DataSet will track the changes.

The DataSet can be considered an in-memory cache of data retrieved from a database. The DataSet consists of a collection of tables, relationships, and constraints. In this example we will show how to use the Delete method on the DataSet to Delete rows from the database.The Database values are updated with those from Dataset using Update method of SqlDataAdapter

Below are some simple steps to preform  Delete operation on Dataset.

STEP  1 : Fill the Dataset with the data you required and bind it to grid.

STEP 2: To Delete a particular row from dataset we required its DatasetIndex, to know the DatasetIndex we perform the delete operation on Grid’s ItemCommand Event.

If e.CommandName = "Delete" Then
End If
dgUser.DataSource = UpdateDatabase(parentset, "OleDb")

STEP 3: Create a new instance of OleDbDataAdapter and pass the required parameters, you can either pass OleDbCommand object or write down the Sql statement alongwith the ConnectionString.

Create a instance of OleDbCommandBuilder, it is used to update the changes from Dataset to Database. The parameter required for OleDbCommandBuilder is OleDbDataAdapter with a SELECT Sql statement. The command builder will automatically generate INSERT,UPDATE & DELETE statements for the table and parameters used in SELECT statement.

Public Function UpdateDatabase(ByRef dataSet As DataSet, ByVal Provider As String) As DataSet
If Provider = "OleDb" Then
Dim dbAdapter As New OleDbDataAdapter("SELECT Sql Statement",ConnectionString)
Dim objCommandBldr As New OleDbCommandBuilder(dbAdapter)
ElseIf Provider = "SQL" Then
Dim sqlAdapter As New SqlDataAdapter("SELECT Sql Statement",ConnectionString)
Dim sqlCommandBuilder As New SqlCommandBuilder(sqlAdapter)
End If

Return dataSet

STEP 4: Build & Execute.

Here is the link to download the sample application which will demonstrate the above behavior.

You can also find a detailed explanation of Updating Database using Dataset over here.

Enjoy Coding and Keep Learning 🙂

Insert Code Snippet – Tip Of Week#1

Hi guys, do you know you can use already ready code inside your visual studio? Yes certainly you can insert code snippets into your code. You can invoke the “Insert Snippet” by using shortcut “ctrl k + ctrl x”

Be Sunshine Happy :)

What makes some people simile and stay sunshine happy, almost all the time? These optimists refuse to get crushed by bad news and spread the sounds of laughter and hope. They are all around us, trying to give those who’re sulking, frowning and sad, a simple lesson in the pursuit of happyness.

Most people are happy if their wishlist is fulfilled. But that’s not real happiness. It’s a fluctuating happiness index which dips if they fall ill or experience heartbreak. Happy energy wouldn’t be dependent on outside factors, it has to come from within. There are people, who have everything they desire and are still unhappy. Choose your emotions and thoughts. Free yourself from past baggage, mistakes and regrets. Choose to be happy.

There’s something about being genuinely happy. Why should your happiness be dependent on tha global economy, your work environment or your spouse’s behaviour?

Moods sway from dark to happy for everyone. Everyone has the power to be totally happy, which is a cultivated art. Can you be really happy in tough times?

Optimism has nothing to do with the future, rather, it is a description of reality. The real definition of optimism was relevent in good and bad times, you just have to choose to be happy, despite whatever happens.

Live life to full, never pay attention to failures. Every minute whatever you do, you should enjoy by saying yes more than by saying no. Always have faith that’s the way to open doors. Once you decide you’ll be happy, that’s what you ‘ll create in your life.

For optimists all experiences are positive, as they bring new opportunity. Hence, happiness is a decision.

Don’t label situations good or bad. When unhappiness onfronts you, rather than running away, exercise the force of will to run through it. It’s not just in thought but in action too. If you have to experiment with new ideas, you’ll experience setbacks. you should not let it intimidate or overwhelm you. Have the will to be happy from inside.

The way to bring happiness is to work honestly and to share. Ther has to be a sense of detachment from external situations.

Work on happiness as a skill to be developed. Let happines be a learnt reaction. You’ll have to work at being happy. But it’ll be rewarding and bring you real joy.

Tell yourself every minute. “It’s in my power to be happy, no matter what!”

How to be Sunshine Happy,

– Don’t label situations or experiences as good or bad.

– Empower yourself to be happy.

– Look within for happiness

– Don’t get affected by bad news

– Choose your emotions. Keep saying, ‘I choose to be happy’

– Conserve your energy, don’t let people sap it

– If you’re hurt, don’t be dependent on anyone else to heal

– Don’t indulge in hurt

– Don’t be imprisoned in you past or have self-pity

Using ParseQueryString to get QueryString Values

Following is the sample code you can use to parse your querystring and return NameValueCollection


protected void Page_Load(object sender, EventArgs e)
String currurl = HttpContext.Current.Request.RawUrl;
String querystring = null ;

// Check to make sure some query string variables
// exist and if not add some and redirect.
int iqs = currurl.IndexOf(‘?’);
if (iqs == -1)
String redirecturl = currurl + "?var1=1&var2=2+2%2f3&var1=3";
Response.Redirect(redirecturl, true);
// If query string variables exist, put them in
// a string.
else if (iqs >= 0)
querystring = (iqs < currurl.Length – 1) ? currurl.Substring(iqs + 1) : String.Empty;

// Parse the query string variables into a NameValueCollection.
NameValueCollection qscoll = HttpUtility.ParseQueryString(querystring);

// Iterate through the collection.
StringBuilder sb = new StringBuilder("");
foreach (String s in qscoll.AllKeys)
sb.Append(s + " – " + qscoll[s] + "");

// Write the result to a label.
ParseOutput.Text = sb.ToString();



This is the front end code ,


<form id="form1" runat="server">
Query string variables are:
<asp:label id="ParseOutput" runat="server">


Hope this Helps 🙂

JQuery in Visual Studio

A big part of the appeal of jQuery is that it allows you to elegantly (and efficiently) find and manipulate HTML elements with minimum lines of code. jQuery supports this via a nice “selector” API that allows developers to query for HTML elements, and then apply “commands” to them. One of the characteristics of jQuery commands is that they can be “chained” together – so that the result of one command can feed into another. jQuery also includes a built-in set of animation APIs that can be used as commands. The combination allows you to do some really cool things with only a few keystrokes.

For example, the below JavaScript uses jQuery to find all <div> elements within a page that have a CSS class of “product”, and then animate them to slowly disappear:


As another example, the JavaScript below uses jQuery to find a specific <table> on the page with an id of “datagrid1”, then retrieves every other <tr> row within the datagrid, and sets those <tr> elements to have a CSS class of “even” – which could be used to alternate the background color of each row:

$(“#datagrid1 tr:nth-child(even)”).addClass(“even”);

The jQuery library also works well on the same page with ASP.NET AJAX and the ASP.NET AJAX Control Toolkit.

Visual Studio figures out external script references, such as to JQuery, by following special reference comments it finds at the top of .js files:

/// <reference path="jquery-1.2.3.js" />

You can download the JQuery from here. You can get more details on JQuery from .

For intellisense support for JQuery you need to install this Hotfix.

Comment for javascript is written inside for intellisense support. JavaScript has the interesting feature that calling toString on a function returns the code of this function including the comments and thus the doc comments. Here’s a similar example in JavaScript where the documentation is written inside of a class constructor:


Another difference with C# or VB.NET is that property and event accessors are two different entities in JavaScript. For this reason, to choose where the documentation should be for those members. Properties should be documented in the getter and events in the “adder” for this reason: