Wednesday, 21 December 2011

How to execute DDL command through ADO.Net ?

SqlConnection mySqlConnection = new SqlConnection("Data Source = LocalServer;Initial Catalog=dbAccount;Integrated Security=True;");

SqlCommand mySqlCommand = mySqlConnection.CreateCommand();

mySqlCommand.CommandText = "CREATE TABLE MyEmployee (ID int CONSTRAINT PK_Persons PRIMARY KEY, FirstName nvarchar(15) NOT NULL, LastName nvarchar(15) NOT NULL, DateOfBirth datetime )";

mySqlConnection.Open();

int result = mySqlCommand.ExecuteNonQuery();
        
mySqlConnection.Close();

How do I split a string by a multi-character delimiter in C# ?

string myString = "This is a new sentence.";
string[] _res = myString
.Split(new string[]{ "is" }, StringSplitOptions.None);
for(int i=0; i<_res.length; i++)
    Console.Write(_res[i]);

Tuesday, 20 December 2011

Difference between Repeater, Datalist, GridView

Repeater:
It contains Header Template, Item template , alternate
Item template and footer template. it can't support
Selection, editing, sorting and paging. this is read only
and fast.

Datalist:
It contains Header Template, Item template , alternate
Item template , Edit item template and footer template. it
can't support sorting and paging but support selection and
editing

GridView:
It contains Header Template, Item template , alternate Item
template , Edit item template and footer template. it can
support selection, editing , sorting and paging. Mostly
every developer caught used this control.

                          Repeater  DataList  GridView  ListView
Flow layout         Yes            Yes            No           Yes
Table layout        No             No            Yes           No
Style propertie    No            Yes            Yes           Yes
Column layout     No            Yes            No           No
Paging                  No             No            Yes          Yes
Sorting                 No            No            Yes           Yes
Edit/Delete          No            No            Yes           Yes
Insert                   No            No            No           Yes
Grouping             No           Yes             No            Yes

Friday, 16 December 2011

Why JSON ?

(1) Because JSON is easy to write. It is just like creating and accessing class in javascript in object notation
(2) If you like Generic Class, you will fall in love with JSON.
(3) JSON is just key : value pairs assigned within an object.
(4) JSON is very fast.
(5) It is easy to understand and can be integrated in any web application very easily.
(6) Better organized data if prepared in well mannered way.
(7) On the server-side you can easily serialize/deserialize your objects to/from JSON.
(8) Almost every browser is giving support for JSON.

What is JSON ?

JSON stands for JavaScript Object Notation that is a language independent text format which is fast and easy to understand.On the server-side you can easily serialize/deserialize your objects to/from JSON.JSON (Java Script Object Notation) provides a simple data format for the exchange of information between the browser and server. In other words JSON is light weight data-interchange format.
An object described in JSON consists of a set of curly braces {} enclosing a set of attribute-value pairs.
For example:
{"movielist": ["Friday the 13th", "Friday the 13th Part 2", "Friday the 13th Part III", "Friday the 13th: The Final Chapter", "Friday the 13th: A New Beginning"]}

Thursday, 15 December 2011

Bulk insert excel to sql ?

sp_configure 'show advanced options' , 1
RECONFIGURE;
Go
sp_configure 'Ad Hoc Distributed Queries' , 1
RECONFIGURE;
GO

SELECT * INTO ItemTemp FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=D:\StudentDetails.xls', [Sheet1$])

Monday, 12 December 2011

How to access ServerSide method from GridView's ItemTemplate

While working with GridView, there may be a case where 
we actually need to do some operations in serverside for 
which we may be in a need to call a server side
method from ItemTemplate of a GridView.

Say for example, 
I had a situation where i need to call a server side 
method (which return a string value) from ItemTemplate.
So i used a label in the ItemTemplate like 


<asp:TemplateField HeaderText="Testing">
<ItemTemplate>
<asp:Label ID="lblCustomerAge" Text='<%# GetCategory() %>' runat="server">
</asp:Label>
</ItemTemplate>
</asp:TemplateField>

Here GetCategory is the server side method.Code-behind is given below

  protected string GetCategory()
    {
       // Do whatever you want here
        return "TestCategory"; // For eg. passing a string
    }

How to open a pop up window with specified location through Javascript

Below is the javascript method that opens a popup with specific height,width,location etc

function openQuadPopup(val) {           
            var width = screen.width - 100;
            var height = screen.height - 100;
            var leftPos = (screen.width - width - 30) / 2;
            var topPos = (screen.height - height - 30) / 2;
            myWindow = window.open('TestPage.aspx?QueryStringValue=' + val, 'NameForPopup', 'menubar=0,resizable=0,width=' + width + ',height=' + height + "'");

            myWindow.moveTo(leftPos, topPos);          
        }