вторник, 30 марта 2010 г.

How to create AJAX AdRotator simple example

First Create a XML as App_Data/Advertisements.xml

<?xmlversion="1.0"encoding="utf-8" ?>
<AlternateText>DotNetCurry Home Page</AlternateText>
<AlternateText>SQL Server Curry Home Page</AlternateText>
<AlternateText>dotnetcurry.com Write For Us</AlternateText>

Code your ASPX as below
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" Interval="2000" runat="server" />

<asp:UpdatePanel ID="up1" runat="server">
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
Runat="server" />

Common SELECT Statements (SQL Server)

Followings are some examples of using SELECT statement. My table name tblTest. Followings are columns. (TestID, TestName, TestDate, TestCity )

1) Select * from tblTest (Returns all columns/Rows)

2) Select * from tblTest Where TestID=2 (Returns the row/s which TestID has value 2)

3) Select * from tblTest where TestID Between 10 and 20 (Return all rows between 10 and 20, this result includes 10 and 20)

4) Select * from tblTest Where TestCity in ('New York','Washington','California') (Returns all rows which city is NewYork, Washington, california)

5) Select * from tblTest Where TestName Like 'A%' (Return all rows where the name starts letter A)

6) Select * from tblTest Where TestName Like '%A' (Return all rows where the name ends letter A)

7) Select * from tblTest Where TestName Like '[ABC]%' (Return all rows of name start with A / B / C)

8) Select * from tblTest Where TestName Like '[^ABC]%' (Return all rows of name not start with A and B and C)

9) Select (TestName+space(1)+TestCity) as Address from tblTest (Returns single column address, name and city added together with a space)

10) Select * from tblTest Where TestName IS NULL (Return all rows which TestNane has null values)

11) Select * from tblTest Where TestName IS NOT NULL (Return all rows which TestNane has not null values)

12) Select * from tblTest Order By TestID Desc (Sort the result set descending order, Asc or not using any sort Ascending order)

13) Select 'Visual Studio' as IDE, '2010' as Version (Creating memory resident result set with two columns[IDE and Version])

14) Select Distinct TestID from tblTest (Returns unique rows based on TestID)

15) Select Top 10 * from tblTest  (Return 10 customers randomly)

16) Select getdate() (Shows the current date)

17) Select db_name() (shows the database name which you are working on)

18) Select @@Servername (Shows name of the server)

19) Select serverproperty ('Edition') (You can pass following ServerName, Edition, EngineEdition, ProductLevel to get current information about the server)

20) Select user_name (Get current user)
21)  Select *  into #test from tblTest  (Create temporary table #test and insert all records from tblTest)
22)  Select Max(TestID) from tblTest (Returns Maximum TestID from tblTest)
23)  Select * from tblTest Compute Max(TestID) (Returns two result sets - getting all rows and maximum value of TestID)

What the difference between div and span tag

The basic difference between them is ,div is block level element and span is inline level element.
<span> and <div> tags both allow a Web designer to style text and add other formatting attributes to their Web page. They are not interchangeable tags, though. <div> tags are block-level elements, whereas <span> tags are not.

<div> tags are block elements that allow you to position elements contained within them


<div style="color:#00FF00">
<h3>Welcome to Studentacad.com</h3>
<p>This is a paragraph.</p>


<span> tags are NOT block elements

<p>This Blog is manage By<span class="blue">Aamir Hasan</span> (CEO)</p>

How to Use Facebook Marketplace

Facebook is the most popular social networking website, with over 200 million active users. Thanks to a partnership with the e-commerce service Oodle, Facebook has upgraded its Marketplace to compete with online marketplaces like Craig's List and eBay. This guide will show you how to use Facebook Marketplace to buy and sell items.

понедельник, 29 марта 2010 г.

Example of simple and effective method for generation of a random password VB .Net

Public Function GeneratePassword(ByVal PwdLength As Integer) As String
    Dim _allowedChars As String = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789"
    Dim rndNum As New Random()
    Dim chars(PwdLength - 1) As Char
    Dim strLength As Integer = _allowedChars.Length
    For i As Integer = 0 To PwdLength - 1
        chars(i) = _allowedChars.Chars(CInt(Fix((_allowedChars.Length) * rndNum.NextDouble())))
    Next i
    Return New String(chars)
End Function

Smart Tips About Visual Studio 2010 Intellisense

Everybody loves visual studio 2008 Intellisense.  One side affect is that when Intellisense window is opened you can't see code beneath it.  But sometimes you need to see the code so you might be pressing ESC button to close Intellisense window.  You might not know that but there is a solution for that.

Press CTRL key while Intellisense window is open it will make your Intellisen window transpart so that you can view the source code beneath it.  Isn't it nice?

Some Useful Shortcuts for Coders in Visual Studio 2010

Followings are some useful shortcuts for coders.

Copy a single line - CTRL+C [Move the insertion point at the begin or end and press space bar, then press the shortcut key combination]
 Cut a single line - CTRL+X [Move the insertion point at the begin or end and press space bar, then press the shortcut key combination]
Comment a line - CTRL+K, CTRL+C [Keep the insertion point any where on line and press ]
UnComment a line - CTRL+K, CTRL+U [Keep the insertion point any where on line and press ]
Put/Remove a break point - F9
Remove all break points as once - CTRL+SHFT+F9 
Expand/Collapse a region- CTRL+M, CTRL+M
Intellisense - Ctrl+Space  [Press CTRL again make the drop down transparent]

пятница, 26 марта 2010 г.

How To Add website url to Bing

As you know for sometime now Microsoft test it new search engine Bing witch will replace MSN live. In the search engine war along with Yahoo and Google, Bing is fight for the second place now. From the SEO point of view Bing is a new search engine with great potential and every website should start add his sitemap to Bing.

Adding your sitemap to Bing is easy:
2. Login with your Live ID or make one if you dont have.
3. Input Website address, sitemap address and webmaster email .

четверг, 25 марта 2010 г.

Foreign Key Relationships FAQ in the Entity Framework

We’re going to look at the designer experience, the EDMX model differences and a few coding examples. We’ll use this extremely simple database model:
Note the fact that the Posts table has a foreign key to the Blogs table.
Designer Experience
Start by creating a new WPF application then add a new ADO.NET Entity Data Model item to it. Choose to generate the model from the database. Open the Tables portion of the treeview and check the Blogs and Posts tables. Note when choosing the tables with which to generate Entities “Include Foreign Key Columns in the Model” is checked by default. This means new models by default will use the new FK associations rather than Independent Associations. Independent Associations were previously the only type of association offered in the Entity Framework and still can be used. If you want just Independent Associations in your model, you’ll need to uncheck the Include FK Columns in the Model checkbox.

After clicking Finish your model should look as follows:
Double click the association and you’ll see the foreign key properties for the relationship:
Let’s leave this as is for now but note it’s possible to switch an existing Association between an FK or Independent Association type. In this case if you wanted to switch an Association to be Independent, you’d press the Delete button in the Referential Constraint dialog. After doing so you’d need to map the Independent Association appropriately and remove the BlogID property from the Post Entity. For now let’s move on without changing the association type.
For comparison sake, add a new entity to the design surface from the toolbox. Once done, right click on the entity and choose Add->Association:
Note that your association doesn’t have to be an FK association (association types can be mixed in the same model). Uncheck the ‘Add foreign key properties to the ‘Blog’ Entity’ check box then Click OK in the dialog. This will let us later look at the model differences between Independent and Foreign Key associations.
So far we’ve: created a WPF project, added an EDM Data Model to it, reverse engineered our Blogs and Posts tables to the model, then added a third entity and created an Independent Association with it.
XML model differences:
We’re going to briefly diverge and look at some of the differences in the XML generated for the different types of associations in our simple model. If you don’t want to do this, feel free to skip to the next section.
Right click on the EDMX file in your project and choose Open With->XML Editor. This will close the design surface and open the contents of the EDMX file in the XML Editor.
Scrolling down, the CSDL XML fragment for our Independent Association looks like this:
<Association Name="Entity1Blog">
<End Type="BlogsModel.Entity1" Role="Entity1" Multiplicity="1" />
<End Type="BlogsModel.Blog" Role="Blog" Multiplicity="*" />
It would also have an MSL XML fragment that tells EF how to traverse the relationship if we’d mapped the new entity & association to storage objects. Since we didn’t complete the mappings the fragment is missing.
The CSDL XML fragment for our FK Associations looks like this:

<Association Name="FK_BlogPost">
          <End Role="Blogs" Type="BlogsModel.Blog" Multiplicity="1" />
          <End Role="Posts" Type="BlogsModel.Post" Multiplicity="*" />
            <Principal Role="Blogs">
              <PropertyRef Name="BlogID" />
            <Dependent Role="Posts">
              <PropertyRef Name="BlogID" />
Notice the ReferentialConstraint element and its contents. There is also no MSL XML fragment for the relationship.
One other thing of interest to note is the Post EntityType has this fragment in the CSDL:
Having the BlogID property on the Post Entity will allow us to directly read & manipulate its value plus use it for data binding (no more need for partial classes with this exposed as a property).
This divergence this tells us three things:
  • EF is handling the two different types of Associations completely differently.
  • If you want to dig into an EDMX and tell what types of Associations you have you can (but looking at the XML can hurt your eyes J).
  • Foreign Key Associations add the parent ID key properties as properties on the child object. This is useful in a number of ways.
Coding experience
Double click on the EDMX file in your project. After clicking Yes, this should reopen the EF Designer for your model. Delete Entity1 from the design surface. This should give you valid model with everything mapped (exactly what you had after running the Add->New Item wizard).
We’re going to run through a few scenarios of how to code against our model. To facilitate, add a button to your WPF form and double click it.
Scenario 1: Adding new Blog and a new Post together by setting Navigation properties.
Note this is what you used to do without FK Associations and is still the recommended way of adding two newdependent objects together. We’ll talk about why in a few minutes. Inside the button event handler add the following code:
using (BlogsEntities ctx = new BlogsEntities())
    Blog myBlog = new Blog { BlogID = 9, Name = "Tim's blog", Owner = "Tim" };
    Post myPost = new Post { PostID = 102, Title = "Post Title", PostContent = "TestContent",
= DateTime.Now, ModifiedDate = DateTime.Now };
    //Nav properties will work immediately.
This code opens a connection to the DB, creates a new blog object, creates a new post object, adds the post object to the blog object’s Posts collection, adds the new blog objects to the context, then saves the changes to the database. Note that as soon as we added the myPost object to the Posts collection of myBlog we could use the navigation properties to traverse between the objects.
Scenario 2: Adding new Blog and a new Post together but set the Post BlogID FK property instead of adding to the myBlog Posts collection.
Delete the code you just placed in the event handler and replace it with the following:
using (BlogsEntities ctx = new BlogsEntities())
                Blog myBlog = new Blog{BlogID = 11, Name = "Tim's blog", Owner = "Tim"};
                Post myPost = new Post{PostID = 101,Title = "Post Title", CreatedDate = DateTime.Now,  
                    ModifiedDate = DateTime.Now, PostContent="Post Content", BlogID = 11};
                ctx.Blogs.AddObject (myBlog);
Note that the navigation properties on the two new objects won’t map to each other until after SaveChanges is called. This is because the context doesn’t know about the parent object yet.
Scenario 3: Adding a new post to an already existing blog.
Replace the code in the event handler with the following:
using (BlogsEntities ctx = new BlogsEntities())
                Post myPost = new Post {PostID = 102, Title = "Post Title", CreatedDate = 
DateTime.Now, ModifiedDate =DateTime.Now, PostContent = "Post Content", BlogID = 11};
                //Nav properties will work immediately b/c the Blog object already exists
Note we never loaded the Blog object into memory. We knew BlogID 11 was a valid ID and set the post.BlogID property directly. Note also, the navigation property for myPost.Blog will work immediately after setting the FK property because the Blog object already exists in the context. Being able to set the property directly enables some previously difficult data binding scenarios as well as can make some coding experiences easier.
These three coding examples show different ways of creating new objects and setting up their relationships using navigation properties and FK associations.

In .NET 4.0 we’ve added support for FK Properties and FK Associations to the Entity Framework. It’s still possible to use Independent Associations and the two can be mixed in models. We’re excited to offer FK Associations because they simplify many common Entity Framework coding tasks. Hopefully this walkthrough has given you a feel for how you can use FK Associations and Properties.

Model First Data Base generation in the Entity Framework 4.0

An exciting new Entity Framework Designer feature in Visual Studio 2010 is the ability to generate DDL that will create a database that can store your entity data model. This feature is not only exciting because it brings a long overdue capability to life, but because it is fully extensible: You can take control of the entire process, or plug into parts of it. For example, you can take over the DDL generation step to add support for your database of choice, or to customize the DDL generation process. Alternatively, you can take over the inheritance mapping step and replace our out-of-the box strategy (which is table-per-type) with your own. Or take over the entire mechanism and generate both stored procedure mappings and CRUD stored procedures for all your types. In a future post, we will show you exactly how to do this and provide an implementation of the table-per-hierarchy mapping for you to use or modify.
For now, let’s take a quick look at this feature by taking a very simple model:
We right click…and in the context menu we see, and click on, “Generate Database Script from Model”:
The database generation wizard asks for a database to target. This information is used by the wizard to determine which database-specific types to translate the Entity Data Model (EDM) types to, and how to render DDL that is appropriate for the target database. In this case, I just created a new Microsoft SQL Server database file:
Once we click on next, we are shown a preview of the generated DDL, which will be saved to disk once we click on “Finish”. Here is an excerpt from the DDL generated now for SQL Server:
-- Creating table 'IngredientSet_Protien'
CREATE TABLE [dbo].[IngredientSet_Protien] (
    [Cut] nvarchar(100)  NOT NULL,
    [Type] nvarchar(70)  NULL,
    [Id] int  NOT NULL
-- Creating table 'IngredientSet_Plant'
CREATE TABLE [dbo].[IngredientSet_Plant] (
    [IsFruit] bit  NOT NULL,
    [IsHerb] bit  NOT NULL,
    [IsVegetable] bit  NOT NULL,
    [Id] int  NOT NULL

-- --------------------------------------------------
-- Creating all Primary Key Constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'RecipeSet'
GO-- --------------------------------------------------
-- Creating all Foreign Key Constraints
-- --------------------------------------------------

-- Creating foreign key on [Chef_Id] in table 'RecipeSet'
    FOREIGN KEY ([Chef_Id])
    REFERENCES [dbo].[ChefSet]
Note here that the default inheritance mapping strategy is to create a table for all subtypes: In the above DDL, you can see that we are generating tables for the Protien and Plant subtypes. These tables are named with the name of the EntitySet in which the types live, to which we append the name of the type itself.
Note also that we generate primary and foreign key constraints for the model.