Monday, November 2, 2009

Development tools

https://browserlab.adobe.com/index.html#

http://viewlike.us

A tool for source-code control that integrates into Basecamp. Very small learning curve, please provide feedback:

https://www.springloops.com/


And a nifty set of tools that might make some jobs easier:

http://web.appstorm.net/roundups/51-web-apps-for-web-designers-and-developers/

Friday, August 28, 2009

Fine Drywall - Home Renovations and Home Additions, Custom Home Building, Drywall Installation, Drywall Contractors

Fine Drywall Ltd - Surrey, BC. Canada | Home Renovations and Home Additions, Custom Home Building, Drywall Installation, Framing Contractors, Drywall Contractors



Fine drywall offers a full suite of drywall related services to its customers.
Fine Drywall specializes in doing new home construction. We also do construction in multifamily units and can readily assist you with updating your home or basement. Furthermore, Fine Drywall has the skills necessary to work on light commercial projects.

New home construction is the primary focus for Fine Drywall. Fine Drywall continues to service many of the top residential builders in the city.

Puneet Singla

As I flow in the river of knowledge throughout my life, I wish to reflect upon & share things that I find fascinating.I have always been passionate about computers & programming. Flying in winds of information overload. keeping a tap on programming, web-design, security and open-source web applications.

Puneet Singla

Thursday, August 13, 2009

.Net Code translation VB.NET to C#.Net And C#.Net to VB.Net



Telrik code convertor

http://www.telerik.com/community/forums/open-source-projects/code-converter.aspx

http://www.carlosag.net/Tools/CodeTranslator/

Puneet Singla

Thursday, August 6, 2009

NUnit Testing Tutorial

NUnit: A tutorial
What is unit testing?

According to Jeff Canna, unit testing ensures that a particular method of a class
successfully performs a set of specific tasks. Each test confirms that a method
produces the expected output when given a known input.

What is NUnit?

NUnit is an open source framework that facilitates unit testing for all .NET languages.

How do I get NUnit?

Download the appropriate file from here and install it. That’s it!!

Writing NUnit tests

One question that crossed my mind when I was learning NUnit was whether I should
create my test project as an executable or as a class library. I finally decided to use a
class library because I wouldn’t be running my test project in a stand-alone manner
anyway. But, creating a test project as an executable would cause no problems. It’s up
to you to decide.

Now, let’s get going. Let us first write the class for which we would write unit test
cases. Our class would be called Arithmetica. It would contain four methods to
perform the basic arithmetic operations – Add, Subtract, Multiply and Divide.
using System;

namespace Arithmetica
{
public class Arithmetica
{
public int Add(int augend, int addend)
{
return augend + addend;
}
public int Subtract(int minuend, int subtrahend)
{
return minuend - subtrahend;
}public int Multiply(int firstFactor, int secondFactor)
{
return firstFactor * secondFactor;
}
public int Divide(int dividend, int divisor)
{
return dividend / divisor;
}
}
}

The above code should be placed in a separate project and compiled into a separate
assembly. That’s how unit testing is performed. The test cases are not a part of the
production code. Implementing unit test within the main assembly not only bloats the
actual code, it will also create additional dependencies to NUnit.Framework.
Secondly, in a multi-team environment, a separate unit test assembly provides the
ease of addition and management. [3]
Now, let’s write the test cases for the Arithmetica class. This would involve the
following steps:
1. Create a new project of “Class Library” type (see discussion above) and name it
Arithmetica.UnitTests.
2. Add the project containing the Arithmetica class into the solution of
Arithmetica.UnitTests.
3. Add reference to nunit.framework.dll. This DLL is located in a directory called bin
under the directory where NUnit is installed.
4. Add the following lines in the class in which you are writing the unit test cases:
using System;
using NUnit.Framework;
5. The class which contains the tests must be declared public and decorated with the
TestFixture attribute as follows:
namespace Arithmetica
{
[TestFixture]
public class ArithmeticaUnitTests
{
}
}
6. Now, you may want to do setup activities which are performed before executing
any test. In our case, we want to create an object of the Arithmetica class. This is done
by decorating the method in which you want to perform the setup activities with the
TestFixtureSetup attribute as follows:
[TestFixture]
public class ArithmeticaUnitTests{
private Arithmetica arithmetica;
[TestFixtureSetUp]
public void SetUp()
{
arithmetica = new Arithmetica();
}
}
Note that a TestFixture can have at most one TestFixtureSetup method.
7. You may also want to perform a set of clean up activities after executing all the
tests. The method which does this is decorated with the TestFixtureTearDown
attribute.
namespace Arithmetica
{
[TestFixture]
public class ArithmeticaUnitTests
{
private Arithmetica arithmetica;
[TestFixtureSetUp]
public void SetUp()
{
arithmetica = new Arithmetica();
}
[TestFixtureTearDown]
public void TearDown()
{
arithmetica = null;
}
}
}
Again, a TestFixture can contain at most one TestFixtureTearDown method. Other
setup and teardown attributes for NUnit include SetUp, TearDown, SetUpFixture and
TearDownFixture. You may refer NUnit documentation for these.
8. Now, let’s write the test for the Add method. Every test method must be decorated
with the Test attribute. You can have as many test methods in a test fixture as you
desire.
[Test]
public void TestAdd()
{
int result = arithmetica.Add(2, 3);
Assert.AreEqual(result, 5);
}
Here, the Add method of Arithmetica class is called with the parameters 2 and 3 and
the sum is stored in result. Then, we check whether result is equal to 5. You can read
more about assertions in NUnit documentation.9. If you are expecting an exception to be thrown in the test method, you can decorate
it with the ExpectedException attribute as follows:
[Test, ExpectedException(typeof(DivideByZeroException))]
public void TestDivide()
{
int result = arithmetica.Divide(2, 0);
}
It must be noted here that the precise type of the exception must be specified in the
ExpectedException attribute. Using Exception instead of DivideByZeroException will
cause the test to fail.
10. Similarly, you may write the other test cases. Here is the listing of the tests that I
wrote:
using System;
using NUnit.Framework;
namespace Arithmetica
{
[TestFixture]
public class ArithmeticaUnitTests
{
private Arithmetica arithmetica;
[TestFixtureSetUp]
public void SetUp()
{
arithmetica = new Arithmetica();
}
[TestFixtureTearDown]
public void TearDown()
{
arithmetica = null;
}
[Test]
public void TestAdd()
{
int result = arithmetica.Add(2, 3);
Assert.AreEqual(result, 5);
}
[Test]
public void TestSubtract()
{
int result = arithmetica.Subtract(3, 2);
Assert.AreEqual(result, 1);
result = arithmetica.Subtract(2, 3);
Assert.AreEqual(result, -1);
}
[Test]
public void TestMultiply(){
int result = arithmetica.Multiply(2, 3);
Assert.AreEqual(result, 6);
}
[Test, ExpectedException(typeof(DivideByZeroException))]
public void TestDivide()
{
int result = arithmetica.Divide(4, 2);
Assert.AreEqual(result, 2);
result = arithmetica.Divide(2, 0);
}
}
}
After this, build the assembly. Please note that the TestFixtureSetUp,
TestFixtureTearDown and Test methods must be defined with the following method
signature:
public void MethodName()


Puneet Singla

Saturday, July 11, 2009

Ten Must-Have Tools Every Developer Should Download Now

NUnit to write unit tests
NDoc to create code documentation
NAnt to build your solutions
CodeSmith to generate code
FxCop to police your code
Snippet Compiler to compile small bits of code
Two different switcher tools, the ASP.NET Version Switcher and the Visual Studio .NET Project Converter
Regulator to build regular expressions
.NET Reflector to examine assemblies


Here is list of must have tools listed by Scott Hanselman's ComputerZen.com




  • THREE WAY TIE: Notepad2 or Notepad++ (Scite also uses the same codebase) or E-TextEditor - The first two are great text editors. Each has first class CR/LF support, ANSI to Unicode switching, whitespace and line ending graphics and Mouse Wheel Zooming. A must. Here's how to completely replace notepad.exe. Personally I renamed Notepad2.exe to "n.exe" which saves me a few dozen "otepad"s a day. Here's how to have Notepad2 be your View Source Editor. Here's how to add Notepad2 to the Explorer context menu. E-TextEditor is new on the block this year, inspired by TextMate in the Macintosh. It includes a "bundle" system that uses the scripting power of the Cygwin Linux-like environment for Windows to provide a more IDE-like experience than Notepad2 or Notepad++. It costs, though, but you should absolutely try it's 30-day trial before you shell out your US$35.


    • Notepad++ is built on the same fundamental codebase as Notepad2, and includes tabbed editing and more language syntax highlighting. Is one better than the other? They are different. I use Notepad2 as a better Notepad, but more and more I find myself using E-TextEditor aka TextMate for Windows when I need to crunch serious text. As with all opinions, there's no right answer, and I think there's room for multiple text editors in my life. These are the three I use.

  • PowerShell - The full power of .NET, WMI and COM all from a command line. PowerShell has a steep learning curve, much like the tango, but oh, my, when you really start dancing...woof. I also use PowerShell Prompt Here.

    • I also recommend after installing PowerShell that you immediately go get PowerTab to enable amazing "ANSI-art" style command-line tab completion.

    • Next, go get the PowerShell Community Extensions to add dozens of useful commands to PowerShell.
    • If you're willing to pay (and wait a little) keep an eye on PowerShell Plus. I'm on the beta, and while it'll cost a reasonable fee, it'll be amazing. Certainly not required, but very shiny.

  • Lutz's Reflector and its Many AddIns - The tool that changed the world and the way we learn about .NET. Download it, select an interesting method and hit the space bar. Take the time to install the Add-Ins and check out the amazing static analysis you can do with things like the Diff and Graph.
  • SlickRun - A free floating dynamic "command prompt" with alias support that continues to amaze. My tips for effective use: read the instructions, edit the slickrun.ini file and bind it to Window-R. Also set ChaseCursor so when you hit Win-R, you'll have a floating transparent command line anywhere your mouse is. I recommend you also use larger fonts! Get to know this little box. It's the bomb. I've tried dozens of launchers, giving each days of actual use, but I keep coming back to SlickRun.

  • FireBug - Arguably the most powerful in-browser IDE available. It's a complete x-ray into your browser including HTML, CSS and JavaScript, all live on the page. A must have.
  • ZoomIt - ZoomIt is so elegant and so fast, it has taken over as my #1 screen magnifier. Do try it, and spend more time with happy audiences and less time dragging a magnified window around. Believe me, I've tried at least ten different magnifiers, and ZoomIt continues to be the best.
  • WinSnap and Window Clippings - I'm torn between two of the finest screenshot utilities I've ever found. Free, clean, fast and tight, WinSnap has as many (or as few) options as you'd like. Also does wonders with rounded corners and transparency. It includes a 32-bit and 64-bit version, as well as a portable no-install version. However, Window Clippings also has no install, includes 32 and 64-bit and is only $10. It's a tough one. I use Window Clippings at least daily, and I use WinSnap a few times a week. Kenny Kerr of Window Clippings is actively adding new features and has a nice clean add-in model on his Developers site. Both these apps are worth your download.

  • CodeRush and Refactor! (and DxCore) - Apparently my enthusiasm for CodeRush has been noticed by a few. It just keeps getting better. However, the best kept secret about CodeRush isn't all the shiny stuff, it's the free Extensibility Engine called DxCore that brings VS.NET plugins to the masses. Don't miss out on free add-ins like CR_Documentor and ElectricEditing.
  • SysInternals - I showed specifically ProcExp and AutoRuns, but anything Mark and Bryce do is pure gold. ProcExp is a great Taskman replacement and includes the invaluable "Find DLL" feature. It can also highlight any .NET processes. AutoRuns is an amazing aggregated view of any and all things that run at startup on your box.


    • A great new addition to the SysInternals Family is Process Monitor, a utility that eclipses both Filemon and Regmon. It runs on any version of Windows and lets you see exactly what a process is doing. Indispensable for developing.
    • It's also worth calling out the legendary Process Explorer as a standout and must-have utility.

  • FolderShare - It takes a minute to grok, but FolderShare lets you synchronize folders between systems, between OS's, behind firewalls. Truly change the way you use your machine. Save a file in a folder and it will always been on your other three machines when you need it. Also access files, if you like, from remote locations. And it's free.



Puneet Singla

Tuesday, July 7, 2009

Pure CSS Menus

here is the list of some good css menus:

http://purecssmenu.com/

http://www.opencube.com/index.asp

http://www.alistapart.com/articles/horizdropdowns

Dropdown Menu
http://www.cssplay.co.uk/menus/pro_dropline7.html

Dropline
http://www.cssplay.co.uk/menus/pro_dropline.html


Puneet Singla

Tuesday, June 23, 2009

SQL Order By clause - List specific values on the top of list

List Specific values on the top in the order by clause

List all the coutries from counties table order by CountryName, but if you need to have "United States" and "Germany" on the top of list.

select * from Countries Order by
CASE Name
WHEN 'United States' THEN 1
WHEN 'Germany' THEN 2
ELSE 100
END,
Name

Puneet Singla

Tuesday, June 9, 2009

Visual Studio shortkuts

Here are some Visual Studio shortcuts that helped me increase my coding speed.
Open Smart Tag: Ctrl + .
Open Smart Tag: Ctrl + .
Cycle Clipboard Ring: Ctrl + Shift + V
Go to Definition: F12
Go to Line: Ctrl + G
Vertical Block Selection: Alt + Mouse or Shift + Alt + Right Arrow
View Properties Window: F4 or Alt + Enter
Comment Selection: Ctrl + K, Ctrl + C
Uncomment Selection: Ctrl + K, Ctrl + U
Toggle Code / Design Views: F7
Incremental Search: Ctrl + I
View Object Browser: Ctrl + Alt + J
Delete Line: Ctrl + L or Shift + Delete
Add New Item to Project: Ctrl + Shift + A
Find All References: Shift + F12
The Rename Refactor: Ctrl + R, R
Find All References: Shift + F12
Format Document: Ctrl + K, Ctrl + D
View Task List: Ctrl + \, Ctrl + T
Find in Files: Ctrl + Shift + F
Toggle Outlining Expansion: Ctrl + M, Ctrl + M
Save Any Output Window: Ctrl + S
Build Solution: Ctrl + Shift + B Ctrl + Shift + V

Puneet Singla

Thursday, June 4, 2009

Javascript Modal Popup

Javascript Modal Popup

http://www.ericmmartin.com/simplemodal/

Agile Carousel: JQuery Carousel Plugin
http://www.5bosses.com/examples/agile_carousel/simple_example/carousel.html

100 Popular jQuery Examples, Plugins and Tutorials
http://www.templatelite.com/100-popular-jquery-plugins/


Spry Sliding Panels widget:

http://www.adobe.com/devnet/dreamweaver/articles/sliding_panel.html

See Sliding panel at techSmith
http://www.techsmith.com/camtasia.asp

Puneet Singla

SQL Server Useful System Stored Procedures

SQL Server Help: Useful System Stored Procedures


SQL Server provides a number of useful system stored procedures that allow you to determine information about the database itself. Note that if you have problems running any of these stored procedures, check that the user you're running them as actually has permissions to execute the stored procedure in question.

Find out which tables and views are in a database
This is simply achieved by making use of the sp_tables system stored procedure, i.e.

EXEC sp_tables

The returned results set contains a list of the tables (and views) in the current database. The TABLE_NAME column gives the name of the table. The TABLE_TYPE column indicates if the table is a TABLE, SYSTEM TABLE or a VIEW. The TABLE_OWNER column is also useful as it shows the table's owner.

Find out which columns are in a database table
This is achieved by making use of the sp_columns system stored procedure, passing in the table name as the parameter, i.e.

EXEC sp_columns 'sales'

The returned results set contains a list of the table's columns. There are quite a few columns in the results set, so only the most useful will be described here:

The COLUMN_NAME column gives the name of the column.
The TYPE_NAME column gives the column's data type.
The LENGTH column gives the column's data type length.
The IS_NULLABLE column shows whether the column accepts null values.

Programmatically display a View's Transact-SQL
The system stored procedure sp_helptext will return a results set containing the lines of Transact-SQL that comprise the View. For example, the following will return the text of the stored procedure Order Details Extended's CREATE VIEW statement:

EXEC sp_helptext 'Order Details Extended'

The text of the CREATE VIEW statement is contained within the Text column of the results set.

Find out which stored procedures are in a database
This is achieved by making use of the sp_stored_procedures system stored procedure,

EXEC sp_stored_procedures

The returned results set contains a list of the stored procedures in the database in which it is executed. in the results set, the PROCEDURE_NAME column gives the name of the stored procedure.

Programmatically display a stored procedure's Transact-SQL
The system stored procedure sp_helptext will return a results set containing the lines of Transact-SQL that comprise the stored procedure. For example, the following will return the text of the stored procedure CustOrdersDetail's CREATE PROCEDURE statement:

EXEC sp_helptext 'CustOrdersDetail'

The text is contained within the Text column of the results set.

Useful Links

Puneet Singla

Monday, June 1, 2009

Friday, May 29, 2009

Flash XML Image Slide Show

Free Flash Image Slide show:

http://www.flabell.com/flash/XML-Image-Slideshow-40

Flash Image slide show with Marquee caption

http://www.lightenna.com/products/website_components/flash_xml_slideshow

DNN Image Rotator
http://www.aboutdnn.com/FreeModule/FlashImageRotator.aspx

Puneet Singla

Decimal, Hexadecimal Character Codes in HTML Unicode convertor

http://code.cside.com/3rdpage/us/unicode/converter.html

Puneet Singla

Wednesday, May 27, 2009

ADO.NET

ADO & Its Limitations - ActiveX Data Objects. Connectivity using this architecture is based on the concept of dedicated connection between the front & the back end. We create a Recordset, connect it to a datasource (often a Database) and work. Changes to the data are updated on the database immediately. The ADO RecordSet is limited in flexibility and functionality. For example, most useful data analysis or presentation requires views of your data that span multiple tables or data sources. Using ADO, this cannot be accomplished without performing a SQL JOIN. As you may or may not know, this is a performance drag. It consumes memory and CPU power on the database server—precious resources especially with today’s Internet user demands. Because a RecordSet is essentially a single result table, navigation is sequential, row-by-row. Thus, if you perform a joining query the resulting data is “flattened”; any relations that may have existed are not relationally navigable.
ADO data types are based on COM/COM+ data types. For example, in COM/COM+ programming the BSTR is typically used to represent strings that need to be interoperable across languages. For those of you who do not know, the BSTR type is a null-terminated string whose leading WORD contains the length of the string. Unfortunately, the BSTR type is really a stranger to all languages and only makes sense in the COM context. For C, C++, and other lower level languages you must use special COM run-time functions to create and destroy them, and rapid application development (RAD) environments like Microsoft Visual Basic® need explicit support in the runtime to handle these types.
Sharing data between components in your application or elsewhere is done through COM marshalling. This limits sharing of data to a COM or COM-friendly environment.
There are also problems with marshalling through firewalls, because they tend to restrict the type of data that can pass through them. COM marshalling requires (COM) system services on the “other side” of the firewall (the server), but firewalls are often set up to block such traffic because it could pose a security threat.


ADO.NET - is a data-access technology that enables applications to connect to data stores and manipulate data contained in them in various ways. It is based on the .NET Framework and it is highly integrated with the rest of the Framework class library.
The ADO.NET API is designed so it can be used from all programming languages that target the .NET Framework, such as Visual Basic, C#, J# and Visual C++.
The ADO.NET stack has two major parts: providers and services.
ADO.NET "providers" are the components that know how to talk to specific data stores (for example, there is a provider to talk to SQL Server databases, and another one to talk to Oracle databases). All providers surface a unified API on top of which other layers can be built.
ADO.NET also includes services built on top of the providers that are designed to facilitate writing applications. One such service is support for an in-memory cache that retains the relational shape of the data, and does change-tracking and constraint validation among other things; this service surfaces through the ADO.NET DataSet, and includes components to interact with the provider layer.
ADO.NET is part of the .NET Framework, so in order to use ADO.NET in your applications all you need is the .NET Framework installed in the computers where your application will be used.
ADO.NET Connection - You use the ADO.NET Connection object to create a connection between your program and a database engine. You will normally keep this connection open just long enough to retrieve or update data. By quickly opening, then closing a connection, you use server resources for as little time as possible. This helps you develop scalable, fast applications that are resource-friendly. The fewer resources you use, the more users you can support on your applications at one time.
If you are creating a database application, you will eventually need to open a connection to that database. An ADO.NET Connection object allows you to create that connection. You will also need to retrieve and modify data in the database, and that is where you will need to use the ADO.NET Command object.
When connecting to SQL Server 7.0 or greater, you use the SqlConnection and SqlCommand objects in the System.Data.SqlClient namespace. When connecting to other OLE DB datasources, use the OleDbConnection and OleDbCommand in the System.Data.OleDb namespace.
To modify data within a database -
1. Create a SqlConnection or an OleDbConnection object and give it a connection string.
2. Open the connection to the database.
3. Create a SqlCommand or an OleDbCommand object and assign to it the connection object you opened.
4. Place an SQL statement into the Command object.
5. Execute the SQL statement by invoking the ExecuteNonQuery method on the Command object.
Dim objConn as SqlClient.SqlConnection
Dim strCon as String
Try
'Create a connection object
objConn=New SqlClient.SqlConnection()

'Build the Connection String
strCon &="Data Source=(local);"
strCon &="Initial Catalog=Northwind;"
strConn &= "User ID=sa;"
strConn &= "Password=;"
objConn.ConnectionString = strConn
objConn.Open() 'Open the Connection

'The connection is now open
'Write your code here
objConn.Close()
Catch oExcept As Exception
MessageBox.Show(oExcept.Message)
End Try
In this event procedure, you first create a new instance of a SqlConnection class. Then you fill in the ConnectionString property prior to opening the connection.
About Connection Strings - A connection string has a set of semi-colon-separated attributes. Each .Net Data Provider connection string looks different, depending on the type of .NET Data Provider you need to use and which attributes are set for each different type of database system. For example, the connection string below is an example of what you use to connect to a local SQL Server. Note that each parameter is separated by a semicolon.
Data Source=(local);Initial Catalog=Northwind;User ID=sa;Password=;
The connection string shown below is an example of how you would connect to a Microsoft Access 2000 database using the OleDbConnection object in System.Data.OleDb.
Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\Northwind.mdb
Parameters in a Connection String - The parameters depends on which data provider is being used.
Server - The name of the SQL Server we wish to access. This is usually the name of the computer that is running SQL server. We may use "local" or "localhost" for local computer. If we are using named instances of SQL server, then the parameter would contain the computer name, followed by a backslash, followed by the named instance of the SQL server.
Database - The name of the database we want to connect to.
User ID - A user ID configured in the SQL Server by the SQL Server administrator.
Password - The password associated with the user ID used.
Note that connection string can also contain the Windows NT account security settings. This is done very simple, by passing the paramater "integrated security=true".
ADO.NET Command Object - The Command object is very similar to the old ADO command object. It is used to store SQL statements that need to be executed against a data source. The Command object can execute SELECT statements, INSERT, UPDATE, or DELETE statements, stored procedures, or any other statement understood by the database. See sample code...

Dim ObjCom as SqlClient.SqlCommand
ObjCom.SqlConnection(strCon)
ObjCom.Connection.Open()
ObjCom.CommandText = "Select * from tblSample"
ObjCom.ExecuteNonQuery()
SqlCommand objects are not used much when we use datasets and data adapters.
Following are some properties of the SqlCommand class...
Connection Property - This property contains data about the connection string. It must be set on the SqlCommand object before it is executed. For the command to execute properly, the connection must be open at the time of execution.
CommandText Property - This property specifies the SQL string or the Stored Procedure.
objCommand.CommandText = "Insert into Employees (empid, empname) values ('EMI0334','Mario Brother')"
Paramaters Collection - If we want to update values in the Employees table above, but we do not know the values at design time, we make use of placeholders. These are variables prefixed with "@" symbol. Our code will look like this...
objCommand.CommandText = "Insert into Employees (empid, empname) values (@empid, @empname)
Next, we have to create parameters that will be used to insert values into the placeholders. For this, we need to add parameters to the parameters collection of the SqlCommand object. This is done so that the values added through the parameters collection & placeholders get included in the SQL statement. Here, parameters mean the parameters to be passed to the SQL statement/Stored Procedures, not the method's parameters.
In order to add parameters to the SqlCommand object, we write the following code...
objCommand.CommandText = "Insert into Employees (empid, empname) values (@empid, @empname)"
objCommand.Parameters.Add("@empID", txtempid.text)
objCommand.Parameters.Add("@empname", txtempname.text)

ExecuteNonQuery Method - Once the connection is open, we run the query in the SqlCommand object using the ExecuteNonQuery method. This is very simple as shown below...
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()
DataReader - In ADO.NET, you no longer have a Recordset. Instead, you have new objects such as DataSets, DataTables, and DataReaders that will be used to retrieve records from data sources.
The DataReader object is a forward-only type of cursor that provides the fastest way to retrieve records from a data source. Because its direction is limited to forward-only, it provides great performance for programmatically processing results or loading list boxes, combo boxes, etc.
Below is code to load a listbox using a DataReader...
Private Sub frmProduct_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
ListLoad()
End Sub

Within the Load Event, we are making a call to ListLoad() Procedure. Note that ListLoad does
not have any constructor, hence we are using MyBase.Load to invoke the constructor of the
class System.Object.

Private Sub ListLoad()
Dim oCmd As SqlClient.SqlCommand
Dim oDR As SqlClient.SqlDataReader
Dim strSQL As String
Dim strConn As String

strConn = ConnectStringBuild()

strSQL = "SELECT ProductName "
strSQL &= "FROM Products"

Try
oCmd = New SqlClient.SqlCommand()
With oCmd
.Connection = _
New SqlClient.SqlConnection(strConn)
.Connection.Open()
.CommandText = strSQL
oDR = .ExecuteReader()
End With

lstProducts.Items.Clear()
Do While oDR.Read()
lstProducts.Items.Add(oDR.Item("ProductName"))
Loop

Catch oExcept As Exception
MessageBox.Show(oExcept.Message)

End Try
End Sub
The code above declares two objects, one for the Command and one for the DataReader.
The Command object holds and executes the SELECT statement to send to the data source. The DataReader is the object that retrieves the data from the result set that comes back from the SELECT statement. Set the Connection property on the Command object to a new instance of a Connection object. You pass a connection string to this new Connection object. After the proper connection string is set, you can open the connection on the command object.
Place the SELECT statement into the CommandText property. When you invoke the ExecuteReader method, the command object submits the SELECT statement to the back end data source. The result is returned and the DataReader object is given a pointer to this result set. The cursor is set just before the first record in this result set.
You will loop through each of the rows in the DataReader by invoking the Read method. The Read method moves the cursor from one row to the next. After the Read method has executed, you can pass the name of the column you wish to retrieve to the Item property on the DataReader. This returns the actual data from that column.
The data returned from the Item property comes back as an Object data type. Because the items you add to the list box are of type Object, no conversion is required when using the Add method of the Items collection on the list box. In this manner, you continue looping until the Read method returns a False. This means you have hit the end of the rows of data that were returned from the SELECT statement.
Here goes the ConnectStringBuild function...
Private Function ConnectStringBuild() As String
Dim strConn As String

strConn &= "Data Source=(local);"
strConn &= "Initial Catalog=Northwind;"
strConn &= "User ID=sa"

Return strConn
End Function

SqlDataAdapter - It is a Data Adapter class for SQL Server databases. It can be used with SQL 2k, SQL 7, MSDE.
Now whats a Data Adapter? -> It is a class that acts as a bridge between the Data Source (means the database)
and the in-memory data objects such as a Dataset. To access a database, a command object is used. We
normally pass a command string and a connection string to the constructor of a Data Adapter. This way, we dont
need to use the SqlCommand Object while retrieving data from the database. We pass the data (using Fill method)
retrieved from the data source through the data adapter to a dataset (or any other in-memory object like a datatable).



Sample Code of filling a textbox with data from a datasource using a data adapter...

Dim con as SqlConnection = New SqlConnection("Server=;Database=;User ID=;Password=;")
Dim strcom as string = "Select * from employees where empid = 334"
Dim da as SqlDataAdapter=New SqlDataAdapter(strcom,con)
Dim ds as dataset
da.fill(ds)
textbox1.datasource = ds
textbox1.databind

Similarly, we can fill a datagrid with data...

Dim con as SqlConnection = New SqlConnection("Server=;Database=;User ID=;Password=;")
Dim strcom as string = "Select * from employees "
Dim da as SqlDataAdapter=New SqlDataAdapter(strcom,con)
Dim ds as dataset
da.fill(ds,"employees")
datagrid1.datasource = ds
datagrid1.databind

NOTE: In the code above, we have passed the name of the table in the Fill method. This is actually not really necessary
until we have more than one table in the data adapter.

Select Command Property (of the Data Adapter)- This property is used to hold the SQL command that is used to
retrieve data from the data source. In the figure above, we can see that the CommandText and Connection are
properties of the Select Command propety. CommandType is also a property of Select Command. See example
below...

Dim da as new SqlDataAdapter
da.SelectCommand = New SqlCommand( )
With da.SelectCommand
.Connection = objConnection
.CommandText = "select * from employees"
End With

Dataset - DataSet object is like an in-memory database. This object holds a collection of DataTable objects. Each
DataTable object is a representation of the data that was retrieved via a SELECT statement or stored procedure
execution. The data in a DataSet can be written out or read in as XML. DataSets also store schema information,
constraints, and relationships between multiple DataTable objects. Through a DataSet you can add, edit, and delete data.

Tuesday, May 26, 2009

Add styles, stylesheets to page header ASP.Net 2.0

To change a page's title:

this.Header.Title = "This is the new page title.";

To add a style attribute for the page:

Style style = new Style();
style.ForeColor = System.Drawing.Color.Navy;
style.BackColor = System.Drawing.Color.LightGray;

// Add the style to the header for the body of the page
this.Header.StyleSheet.CreateStyleRule(style, null, "body");

To add a stylesheet to :

HtmlLink link = new HtmlLink();
link.Attributes.Add("type", "text/css");
link.Attributes.Add("rel", "stylesheet");
link.Attributes.Add("href", "~/newstyle.css");
this.Header.Controls.Add(link);

LINQ Framework Design Guidelines

here is a very good resource on LINQ design guidelines that you can read more on it here:

LINQ Framework Design Guidelines (http://blogs.msdn.com/mirceat/archive/2008/03/13/linq-framework-design-guidelines.aspx)

Tuesday, May 19, 2009

Introducing LINQ Tutorial

http://msmvps.com/blogs/abu/archive/2008/06/30/introducing-linq-tutorial.aspx

  • Part 1: Introduction to LINQ to SQL
  • Part 2: Defining our Data Model Classes
  • Part 3: Querying our Database
  • Part 4: Updating our Database
  • Part 5: Binding UI using the ASP:LinqDataSource Control
  • Part 6: Retrieving Data Using Stored Procedures
  • Part 7: Updating our Database using Stored Procedures
  • Part 8: Executing Custom SQL Expressions
  • Part 9: Using a Custom LINQ Expression with the control
  • Useful Features in SQL Server 2008

    Useful Features in SQL Server 2008

    Encryption at rest

    Whole databases can be encrypted with a master key (which can be stored in an HSM), rather than encrypting by each column. No code changes are required, hence this feature is called Transparent Data Encryption. It gives true encryption of data at rest, included backup files.

    Filtered indexes

    An index can be created with a filter (i.e. index all rows where MyDateField is not null), thus making much more meaningful indexes &rarrow; improved performance.

    Sparse columns support

    There are times when you want to create say 20 columns, only a portion of which will be used at any given time (perhaps there are multiple applications using the table, and they each have a few unique needs). If you create all these columns, your table becomes a little unwieldy in many ways. You can use an XML column to store just the subset required, or in 2008 you can use the new sparse columns feature. This will improve indexing and manageability.

    Performance Data Collector

    The new Performance Data Collector stores query information in a data warehouse, making it easy to answer questions like "whose query was hogging the resources this morning, causing my job to get a timeout?"

    Resource Governor

    Allows the administrator to allocate resource slices to different users or classes of users; thus for instance you could specify that the core processing user would always get (if needed) a minimum of 40% of the CPU & RAM, and you could specify that the marketing users (once they have beefy report models to work with) never get more than 10% of the resources. For example.

    Report Builder

    The Reporting Services Report Builder has been entirely redesigned — now looks like an Office 2007 application. The table and matrix controls have been replaced with a far more flexible tablix control that allows you to do all kinds of cool things.

    Integration Services

    These upgrades are basically in the area of performance improvements, particularly with regard to the Lookup data flow task. Other improvements / new functionality: ADO.Net as default data source (rather than OLEDB); data profiling task; C# as new / default language for scripting tasks.

    Transact SQL / Database Engine

    Finally, we get to the heart of SQL Server: the structured query language. Supposedly this thing is much faster. There is some new syntax available: GROUPING SETS for enhanced BI-type queries; MERGE to perform inserts, updates, and deletes in one statement; the+= operator, and more. There's also the new Change Data Capture for enhanced auditability and better incremental bulk loads.




    Multiple Insert Rows

    SQL Server 2008 supports the option of inserting multiple records in one statement. Each row of data is followed by a comma until reaching the last row where the INSERT command is completed like normal.

    INSERT INTO Customers
    (CustID, CustName)
    VALUES
    ('Cust1', 'Smith Company'),
    ('Cust2', 'Perform Company'),
    ('Cust3', 'Test Inc');

    Other version of SQL Server require a separate statement to be executed for each record insert.

    Friday, April 24, 2009

    Image galleries

    Very Nice Image Galleries

    http://smoothgallery.jondesign.net/showcase/gallery/#

    http://dhtmlsite.com/imagegalleries.php

    http://highslide.com/

    http://www.dhtmlgoodies.com/scripts/image_slideshow/image_slideshow.html

    http://joshuaink2006.johnoxton.co.uk/templates/gallery/index.htm

    http://sonspring.com/journal/slideshow-alternative

    http://iamacamera.org/sandbox/photoshuffler/

    Very Nice Image Slide show
    http://www.cfcms.nl/voorbeelden-van-cfcms-systemen.html

    Nice tool tip & On Image Hover Shows nice image gallery
    http://www.catswhocode.com/blog/how-to-create-a-fancy-image-gallery-with-jquery

    FLASH Image Galleries

    http://www.visual-blast.com/flash/free-flash-gallery-solutions-for-your-images/