Hot News!

Not Available

Click Like or share to support us!

Nov 2, 2012

Now available: No-Cost, No-Touch App Lifecycle Management for Lean Teams


It's available now. It's Team Foundation Service, a new way for teams who care about rapid software delivery to plan and manage projects. And for teams up to 5 developers, it's free.

Writing code is fun, but managing development can be complicated. Do you keep your code under version control? Where do you keep track of bugs and new features? How do you keep your team on the same page? Now you can utilize Team Foundation Service to do all these things today, with zero additional infrastructure.

Stop standing up servers. Stop installing and configuring multiple pieces of software to support your development process. With Team Foundation Service, you get an easy-to-use and easy-to-administer cloud-based solution that handles the critical elements of application lifecycle management, such as version control, agile planning and automated builds. Now available for development teams worldwide, Team Foundation Service benefits include:
Accessible from anywhere, using existing and familiar tools.
Plan projects, collaborate with your team, and manage your code online from anywhere using any modern web browser. Works with all editions of Visual Studio 2012 (even Express!), as well as Eclipse and other tools (by using our command line client).
Get started quickly, with no infrastructure to manage.
Go from "sign up" to your first project in minutes, and set up a Continuous Integration (CI) build in a few easy steps. Your source code and work items are stored in the cloud, making server configuration a thing of the past.
All languages and platforms welcome.
From C# to Python, from Windows to Android, you can use a variety of languages and target a variety of platforms. Our services are designed to help you focus on what you do best—building great apps.

Get started today by signing up for your free account!

Team Foundation Service is being made available to teams of up to five developers for FREE. Sign up today, invite up to four team members and start collaborating for no cost. To get started, visit: http://tfs.visualstudio.com.


Jul 2, 2012

C#: Storing and Retrieving Images from SQL Server Using Strored Procedures

Introduction

First of all I have to tell you I am not a Expert but I will try by best to explain the solution. In this article I am going to explain how to store and retrieve image from SQL server database by using C# as the front end programming language and Stored Procedures as the back end language for SQL server. Reason to write article about this topic is give proper understanding for the beginners.

Prerequisites

You need basic knowledge about Stored Procedures and C# language.

Tools Used

  • SQL Server 2008
  • Visual Studio 2010
  • C# (Windows Form Application)

Preparing the Development Environment

SQL Server Environment

Creating Tables
In this example I am going to use only one table call ImageData and it only contain two fields call ImageID and other one is call ImageData, data types of this fields are int and image. Use below SQL script to create table.
 CREATE TABLE [dbo].[ImageData]
 (
    [ImageID] [int] IDENTITY(1,1) NOT NULL,
    [ImageData] [image] NULL,
 CONSTRAINT [PK_ImageData] PRIMARY KEY CLUSTERED 
 (
    [ImageID] ASC
 )
 WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, 
 ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
 ) 
 ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  
Creating Stored Procedures
In this example I am going to use Four(4) Stored Procedures call ReadAllImage, ReadAllImageIDs, ReadImage, SaveImage and use below SQL scripts to create those Procedures.
CREATE proc [dbo].[ReadAllImage] as 
SELECT * FROM ImageData 
GO
CREATE proc [dbo].[ReadAllImageIDs] as 
SELECT ImageID FROM ImageData 
GO
CREATE proc [dbo].[ReadImage] @imgId int as 
SELECT ImageData FROM ImageData 
WHERE ImageID=@imgId 
GO 
CREATE proc [dbo].[SaveImage] @img image as
INSERT INTO ImageData(ImageData)
VALUES (@img)
GO

Visual Studio Environment

Creating Windows Form
In this exapmle I am going to use only one Form and set basic properties according to the below table.

Control Name
Property Name
Property Value
Form
Name
UsingSPs
Text
Storing and Retrieving Images from SQL Server using C#.NET
Button1
Name
btnLoadAndSave
Text
<<--Load and Save Image-->>
Button2
Name
btnRefresh
Text
Refresh
Button3
Name
btnDisplayImage
Text
Display Image
ComboBox
Name
cmbImageID
GroupBox
Name
grbPicBox
Text
Image Display
Anchor
Top, Bottom, Left, Right
PictureBox
Name
picImage
Dock
Fill

Start Cording

Now we have all the things to start our cording and this is the part we have to get better concentrate of our development. Anyway I will try my best to explain the cording, then let's start our journey.
In this example I am going to use one more class call DBHandler other than the From, purpose of this class is to handle the database connection details. Here is the code for that class.

Handling Database Connection String

public class DBHandler
{        
  public static string SrvName = @"DBSERVER"; //Your SQL Server Name
  public static string DbName = @"DB";//Your Database Name
  public static string UsrName = "us";//Your SQL Server User Name
  public static string Pasword = "xxxx";//Your SQL Server Password
        
  /// <summary>
  /// Public static method to access connection string throw out the project 
  /// </summary>
  /// <returns>return database connection string</returns>
  public static string GetConnectionString()
  {
     return "Data Source=" + SrvName + "; initial catalog=" + DbName + "; user id=" 
     + UsrName + "; password=" + Pasword + ";";//Build Connection String and Return
  }
}

Select and Store Image to Database

Before Start the Coding add below namespaces to your code.
using System.IO;
using System.Data;
using System.Data.SqlClient;
Here I am going to explain the btnLoadAndSave button click event process step by step.
  1. Create Connection to the Database.
  2. Create object call fop of type OpenFileDialog.
  3. Set InitialDirectory Property of the object fop.
  4. Set Filter Property of the object fop(in here user can select only .jpg files)
  5. Display open file dialog to user and only user select a image enter to if block.
  6. Create a file stream object call FS associate to user selected file.
  7. Create a byte array with size of user selected file stream length.
  8. Read user selected file stream in to byte array.
  9. Check whether connection to database is close or not.
  10. If connection is close then only open the connection.
  11. Create a SQL command object call cmd by passing name of the stored procedure and database connection.
  12. Set CommandType Property of the object cmd to stored procedure type.
  13. Add parameter to the cmd object and set value to that parameter.
  14. Execute SQL command by calling the ExecuteNonQuery() method of the object cmd.
  15. Call user defined method to load image IDs to combo box. (this method will explain later so don't worry now)
  16. Display save successful message to user.
  17. Catch if any error occur during the above code executing process.
  18. Finally Check whether connection to database is open or not, if connection is open then only close the connection.
Below Demonstrate the Complete Select and Store image to database code.
SqlConnection con = new SqlConnection(DBHandler.GetConnectionString());
try
 {
   OpenFileDialog fop = new OpenFileDialog();
   fop.InitialDirectory = @"C:\"; 
   fop.Filter = "[JPG,JPEG]|*.jpg";
   if (fop.ShowDialog() == DialogResult.OK)
   {
     FileStream FS = new FileStream(@fop.FileName, FileMode.Open, FileAccess.Read);
     byte[] img = new byte[FS.Length];
     FS.Read(img, 0, Convert.ToInt32(FS.Length));

     if (con.State == ConnectionState.Closed)
       con.Open();
     SqlCommand cmd = new SqlCommand("SaveImage", con);
     cmd.CommandType = CommandType.StoredProcedure;
     cmd.Parameters.Add("@img", SqlDbType.Image).Value = img;
     cmd.ExecuteNonQuery();
     loadImageIDs();
     MessageBox.Show("Image Save Successfully!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
   }
   else
   {
     MessageBox.Show("Please Select a Image to save!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
   }

 }
 catch (Exception ex)
 {
   MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
 finally
 {
   if (con.State == ConnectionState.Open)
     con.Close();
 }

Retrieving and Display Image

Here I am going to explain the btnDisplayImage button click event process step by step.
  1. Check whether user select image ID or not from combobox.
  2. Check whether picture box contain image or not.
  3. Clear the image of the picture box if there is image.
  4. Create Connection to the Database.
  5. Create a SQL command object call cmd by passing name of the stored procedure and database connection.
  6. Set CommandType Property of the object cmd to stored procedure type.
  7. Add parameter to the cmd object and set value to that parameter.
  8. Create SQL data adapter object call adp by passing previously created cmd object.
  9. Create a data table object call dt to hold result of the cmd object.
  10. Check whether connection to database is close or not.
  11. If connection is close then only open the connection.
  12. Object dt fill with data by calling the fill method of adp objec.
  13. Check whether object dt contain any data row or not.
  14. Ccreate memory stream object call ms by passing byte array of the image.
  15. Set image property of the picture box by creating a image from memory stream.
  16. Set SizeMode property of the picture box to stretch.
  17. Call refresh metod of picture box.
  18. Catch if any error occur during the above code executing process.
  19. Finally Check whether connection to database is open or not, if connection is open then only close the connection.
Below Demonstrate the Complete Retrieving and Display Image code.
if (cmbImageID.SelectedValue != null)
{
    if (picImage.Image != null)
        picImage.Image.Dispose();

    SqlConnection con = new SqlConnection(DBHandler.GetConnectionString());
    SqlCommand cmd = new SqlCommand("ReadImage", con);
    cmd.CommandType = CommandType.StoredProcedure; 
    cmd.Parameters.Add("@imgId", SqlDbType.Int).Value = 
              Convert.ToInt32(cmbImageID.SelectedValue.ToString());
    SqlDataAdapter adp = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    try
    {
        if (con.State == ConnectionState.Closed)
            con.Open();
        adp.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            MemoryStream ms = new MemoryStream((byte[])dt.Rows[0]["ImageData"]);
            picImage.Image = Image.FromStream(ms);
            picImage.SizeMode = PictureBoxSizeMode.StretchImage;
            picImage.Refresh();
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error", 
              MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    finally
    {
        if (con.State == ConnectionState.Open)
            con.Close();
    }
}
else
{
    MessageBox.Show("Please Select a Image ID to Display!!", 
       "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Jul 1, 2012

របៀបប្តូរ Keyboard Layout ក្នុង VB.NET

ចំពោះ​អ្នក​សរសេរ​កម្ម​វិធី​ទាំងឡាយ ដែលប្រើ​ប្រាស់ខ្មែរ​យូនីកូដ នៅ​ពេល​ដែល​ចង់ប្តូរពី Keyboard Layout english ot khmer Unicode នោះ លោក​អ្នក​តំរូវអោយ​អ្នក​ប្រើ​ប្រាស់​កម្ម​វិធីចុច alt + Shift ដើម្បី​ប្តូរ​។ សកម្មភាព​បែប​នេះ វា​អាចបណ្តាលអោយ​មានកំហុស​កើត​ឡើង​ក្នុង​កម្ម​វិធី ឧទាហរណ៍ Text box ដែល​ត្រូវ​តំរូវ​អោយអ្នក​ប្រើប្រាស់បញ្ចូលទិន្ន​ជាលេខជាដើម ប្រសិន​បើ​ Keyboard Layout ស្ថិត​ក្នុង​ស្ថានភាព khmer (CA or KH) នោះ​វាបណ្តាល​អោយមានកំហុស​កើ​តឡើង។ ដើ​ម្បី​ដោះ​ស្រាយ​បញ្ហានេះ​លោក​អ្នក​ត្រូវ​ប្តូរ​ Keyboard Layout តាមរយៈការសរសេរ​កូដ នៅ​ត្រង់​ព្រឹត្តិការណ៍ got Focus ទៅ​លើ​ object មួយ ។ ខាង​ក្រោមនេះ គឺ​ជាគំរូកូដ​សំរាប់ផ្លាស់ប្តូរ Keyboard Layout ទៅ​ជាភាសាខ្មែរ រី ជាភាសា​អង់គ្លេស។
Module Module1
Public Declare Function GetKeyboardLayoutName Lib “user32″ _
Alias “GetKeyboardLayoutNameA” _
(ByVal pwszKLID As String) As Long
Public Declare Function LoadKeyboardLayout Lib “user32″ _
Alias “LoadKeyboardLayoutA” _
(ByVal pwszKLID As String, ByVal flags As Long) As Long
Const KLF_ACTIVATE = &H1
‘ some languages code
Public Const LANG_ENGLISH As String = “00000409″
Public Const LANG_FRENCH As String = “0000040C”
Public Const LANG_ARABIC As String = “00000401″
Public Const LANG_GREEK As String = “00000408″
Public Const Lang_kh As String = “a0000403″
Public Const LANG_ITALIAN As String = “00000400″
Public Const LANG_GERMAN As String = “00000407″
Public Function SwitchKeyboardLang(ByVal strLangID As String) As Boolean
‘Returns TRUE when the KeyboardLayout was set properly, FALSE otherwise
Dim strRet As String
On Error Resume Next
strRet = New String(“0″, 9)
GetKeyboardLayoutName(strRet)
If strRet = (strLangID & Chr(0)) Then
‘ you are try to switch to the already selected language
‘ so return without doing anything
SwitchKeyboardLang = True
Exit Function
Else
strRet = New String(“0″, 9)
strRet = LoadKeyboardLayout((strLangID & Chr(0)), KLF_ACTIVATE)
End If
GetKeyboardLayoutName(strRet) ‘ Test if switch successed
If strRet = (strLangID) Then
SwitchKeyboardLang = True
End If
End Function
End Module
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Text = SwitchKeyboardLang(LANG_ENGLISH)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Text = SwitchKeyboardLang(Lang_kh)
End Sub
End Class
Source: http://laingmoam.wordpress.com/2010/01/11/%E1%9E%9A%E1%9E%94%E1%9F%80%E1%9E%94%E1%9E%94%E1%9F%92%E1%9E%8F%E1%9E%BC%E1%9E%9A-keyboard-layout-%E1%9E%80%E1%9F%92%E1%9E%93%E1%9E%BB%E1%9E%84-vb-net/

Jun 12, 2012

Tip: Importing Data from MS Access 2010 64-bit .accdb database into SQL Server using SSIS

Problem:
You can’t connect using Native OLEDB \Microsoft Jet 4.0 OLEDB Provider.  It fails with following error message:
Test connection failed because of an error in initializing provider. Unrecognized database format 'C:\Users\vishah\Documents\myDB.accdb'.

Solution:

image

Tip: Importing Microsoft Access 2007 Database Tables into SQL Server

Microsoft SQL Server 2005 and 2008 offer the Import and Export Wizard to move data to and from an external source. You can also create a basic SQL Server Integration Services (SSIS) package which can be used later in the Business Intelligence Development Project.
With the Import and Export wizard, you can access different types of data sources. These sources include database formats such as Microsoft Access, Microsoft SQL Server, flat files, Microsoft Excel, and Oracle. This article discusses importing Access 2007 database tables into MS SQL Server 2005/2008.
Importing Microsoft Access MDB databases (2003-format or earlier) is a built in feature of SQL Server. However, because of the difference between the database engine of Microsoft Access 2007 and earlier versions, it is not possible to connect to the Access 2007 database (*.ACCDB) using the built-in data source “Microsoft Access”. To import data from a Microsoft Access 2007 database, you must install the OLEDB Provider for Microsoft Office 12.0 Access Database Engine. Refer to the following FMS tip for details:
After installing this driver, open SQL Server Management Studio and connect to the desired instance of SQL Server database engine. In the Object Explorer, it shows database list available in that instance of SQL Server. Select a desired database or create a new one. Right Click this database and select Tasks -> Import Data.

Now follow the several pages of the wizard. The steps below detail how to import data into a SQL Server 2005 database, but the steps are very similar in SQL Server 2008.
On the first page, select the Data source from which you want to import the data. There are several data sources also available such as:
  • Microsoft OLEDB provider for SQL Server
  • Microsoft OLEDB provider for Oracle
  • SQL Native Client
  • Microsoft Access
  • Microsoft Excel, etc…
Because of the difference between the database engine of Microsoft Access 2007 and earlier version of Microsoft Access, it is not possible to connect to the Access 2007 database using data source “Microsoft Access”. You can use this if you wish to import data from a MDB format, but not an ACCDB from Access 2007.
If you have properly installed the 2007 Office System driver, you will see another Data Source option: “Microsoft Office 12.0 Access Database Engine.”


May 24, 2012

Bump Photos to your Computer!


One of the reasons people love Bump is that it's the fastest and simplest way to share photos with friends and family.  Bumping photos has been the most popular way to use Bump -- tens of millions of people have already bumped more than 600 million photos in the last two years.
When we talk to people who use Bump, they often tell us how they love that Bump just makes sense to them.  If they want to share a photo with a friend or family member, they don't have to understand complicated technology -- they can just bump their phones together.  But one of their biggest complaints is that it is hard to get photos off their phone and onto their computer.  Syncing is complicated and often requires a cable you just can't find, and people are fed up with emailing their own photos to themselves.  Users would often jokingly tell us, "Bump is great; if only my computer could Bump too!"
So we built it.
Starting today, everyone who uses Bump can go to http://bu.mp on their computer web browser to bump photos from their phone directly to their computer.  There's no software to install -- it all runs in your browser.  You simply select the photos in the Bump app on your phone and then gently bump the spacebar on your keyboard... and voila!  Your photos will instantly appear on your computer.  It's how technology should work.
From there, you can save them to your hard drive or get a short link to share with friends on Facebook, Twitter, email, or IM (we host the photos for free, no limits).  Bump works with modern versions of most of the popular web browsers, including Safari, Chrome, and Firefox.
Watch the quick demo video, or better yet, go try it yourself at http://bu.mp.  
We hope you enjoy it!
-dave and the Bump Team

May 14, 2012

C#: How to Search Text in ListBox Items from TextBox

//Write in Event TextBox1_TextChanged

private void TextBox1_TextChanged(object sender, EventArgs e)
{
  ListBox2.Items.Clear();
  ListBox1.Sorted = true;

  //search
  foreach (string element_in_listbox in ListBox1.Items){
     if (TextBox1.TextLength <= element_in_listbox.Length) { 
       if ( TextBox1.Text== element_in_listbox.Substring(0, TextBox1.TextLength)){
            ListBox2.Items.Add(element_in_listbox);
        }
     }
  }

  //select first index
   if (ListBox2.Items.Count != 0) ListBox2.SelectedIndex = 0;
}

Apr 30, 2012

How to Install SQL server 2008 on Windows 7


First you need the installer, download it from here.
Requirements:
Visual Studio 2010 or VS 2008 SP1
Step 1: Double click on the installer. It will take some time to extract. After that an window  will open as follow.
First window of installation
Step 1
Step 2: From this window click on the Installation menu (See Left). Now there will be appear some option under Installation. From right, click on the option New SQL Server stand-alone installation or add features to an existing installation.
Note: After Clicking on that a window may appear as bellow. Just click on the button Run Program of that.
Click Run Program
Note
Step 3: Now setup will take a moment to complete some operation. To continue there can not be any operation with status failed. If any operation fails then it will not be possible to continue installation. Click OK
Every operation should be passed
Step 4

Mar 29, 2012

C/C++: First C Program

#include 
#include
main(){

 printf("Hello, this is my first program");
 getch();

}


Out put: Hello, this is my first program


Jan 13, 2012

Printing Component

Providing support for Printing is one of the common tasks during application development. The .NET Framework provides excellent support for Printing documents.
PrintDocument Component
In the .NET Framework, a printed document is represented by the PrintDocument component. The PrintDocument object encapsulates all the information needed to print a page.  They handle the events and operations of printing. The PrintDocument object exposes three properties which are as follows:
PrinterSettings Property: Contains information about the capabilities and settings of the printers.
DefaultPageSettings Property: Encapsulates the configuration for printing each printed page.
PrintController Property: Describes how each page is guided through the printing process.
How Printing Works?
Printing content is provided directly by the application logic in the .NET Framework. You add a PrintDocument object to the project and handle the PrintPage event which is called every time a new page is to be printed. A print job is initiated by the PrintDocument's Print method. This starts the print job and raises one or more events. When the print job begins, aBeginPrint event occurs, followed by the PrintPage event for each page, followed by the EndPage event when the job is done. If the print job contains multiple pages, one PrintPage event will be raised for each page in the job making the PrintPage event to execute multiple times. The PrintPage event is the main event involved in printing documents. To send content to the printer you must handle this event and provide code to render the content in the PrintPage event handler.
PrintDialogs
Print dialogs are supported by the PrintDialog class and they allow us to print the document. To print a document we need to set the Document property of the PrintDialog to PrintDocument object and PrinterSettings to PrinterSettings object. You can print the document by assigning PrintDialog object's PrinterSettings property to the PrinterSettings property of the PrintDocument object and use the PrintDocument object's Print method.
Properties of the Print Dialog are as follows:
AllowPrintTofile: Gets/Sets whether the Print to file checkbox is enabled.
AllowSelection: Gets/Sets whether the selection radio is enabled.
AllowSomePages: Gets/Sets whether the From...To...Page radio button is enabled.
Document: Gets/Sets the PrintDocument used to obtain PrinterSettings.
PrinterSettings: Gets/Sets the PrinterSettings dialog box to modify.
PrintToFile: Gets/Sets whether the Print to file checkbox is enabled.
ShowHelp: Gets/Sets whether the Help button is displayed.
ShowNetwork: Gets/Sets whether the network button is displayed.
PrintPreviewDialog
Print Preview dialogs are supported by the PrintPreviewDialog class and they allow us to preview the document before printing. You can preview a document by setting the Documentproperty of the PrintPreviewDialog object to the PrintDocument object. Once set, the PrintPreviewDialog provides functionality to zoom, print, to view multiple pages of the preview, etc.
PrintPreviewControl
PrintPreview control allows to create our own custom previews. They display print previews and you can use it to create your own custom print preview windows. To use this control you need to set the print document to it's Document property. 
Notable properties of the PrintPreviewControl are as follows:
AutoZoom: When True (default), resizing the control automatically zooms to make all contents visible.
Columns: Gets/Sets the number of pages displayed horizontally.
Rows: Gets/Sets the number of pages displayed vertically.
StartPage: Gets/Sets the apge number of the upper left page.
Zoom: Gets/Sets a value specifying how large the pages will appear.
PageSetupDialog
Page Setup dialogs are used to specify page details for printing. This dialog allows us to set borders and adjustments, headers and footers, portraits, orientation, etc. You use thePrinterSettings property of this dialog to get a Printer Settings object that holds settings the user specified. The PageSetupDialog exposes a Document property that specifies the PrintDocument to use. Setting the Document property binds the specifed PrintDocument to the PageSetupDialog and any changes made in this dialog are updated in the PrinterSettings property.