Wednesday, October 16, 2013

Formatting Numbers by padding with leading zeros in SQL Server

DECLARE @empNumber INT = 7123
SELECT STUFF('000000', 6-LEN(@empNumber)+1, LEN(@empNumber), @empNumber)
Or, as per your query

SELECT STUFF('000000', 6-LEN(EmployeeID)+1, LEN(EmployeeID), EmployeeID)
         AS EmployeeCode
FROM dbo.RequestItems
WHERE ID=0

You can change your procedure in this way

SELECT Right('000000' + CONVERT(NVARCHAR, EmployeeID), 6) AS EmpIDText,
       EmployeeID
FROM dbo.RequestItems
WHERE ID=0
However this will change your EmployeeID to a string, so I suggest to add again the original numeric value

Friday, September 13, 2013

How to Display Date and Time in your Grails Application

I am going to show you how you can accept Data and Time from the user as input using 'Jquery Date Time Picker Plugin'.

You can read more about the plugin here.

Step 1:

In BuildConfig.groovy, add the following code in plugins tag as:

plugins { 
    compile ":jquery-ui:1.8.24" 
    compile ':jquery-date-time-picker:0.1.0'
}

Step 2:

In Config.groovy, add the following code:

Monday, September 9, 2013

DiffMerge : A Merging tool for Git

When using the distributed Version Control i.e. Git, your files might conflict since multiple users might have been working on same file.

Hence, you can use any text editor which is boring, tiresome and hard to identify where the issue is. The best option is to use a merging tool such as Diff Merge. (Click on the link to go to the downloads page)

I faced one configuration issue when I was trying to use it for the first time.
The error was "Unexpected Parameter". The configuration from the software manual didnot work for me.

The solution is to edit the .gitconfig file manually to look like the following.

The following commands in a Command Prompt window will update your .gitconfig to configure GIT use DiffMerge:

C:\> git config --global diff.tool diffmerge
C:\> git config --global difftool.diffmerge.cmd "C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe \"$LOCAL\" \"$REMOTE\""

C:\> git config --global merge.tool diffmerge
C:\> git config --global mergetool.diffmerge.trustExitCode true
C:\> git config --global mergetool.diffmerge.cmd "C:/Program Files/SourceGear/Common/DiffMerge/sgdm.exe  --merge --result=$MERGED $LOCAL $BASE $REMOTE" trustExitCode = true keepBackup = false


The code snippet that is Bold is the major change made.

Grails : Displaying Error Message on View which is thrown from the Service Layer

In your controller class, enclose the code that calls the service in a try-catch block.

Example:
try {

def searchResult = User.getUserByName(params.name)

if(searchResult != null)
render(view: "/admin/user/list", model: [userInstanceList: searchResult?.results, userInstanceTotal: searchResult?.total])

else{

flash.message = message(code: 'user.nonfound.message', default: "No items found.")
render(view: "/admin/user/list", model: [userInstanceList: [], userInstanceTotal: 0])
}
} catch (e) {

flash.message = message(code: 'user.nonfound.message', default: "No items found.")

render(view: "/admin/user/list", model: [userInstanceList: [],userInstanceTotal: 0])
}

Wednesday, September 4, 2013

Sending Email from your Grails Application : A Tutorial

Here is how you can simply send an email from your Grails Application.


Step 1: In BuildConfig.groovy add the ff code in plugins{} tag,

// Grails mail plugin
compile ":mail:1.0.1"

Step 2: In Config.groovy, add the ff code
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "sample@gmail.com"
password = "fakeP@SSw0Rd"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}

Solving: "No result defined for action ... and result input"

When programming in Java and using the Struts 2 Framework, the program threw the exception "No result defined for action ... and result input".

The solution was to add an input redirection like.

<result type="dispatcher" name="input">/WEB-INF/jsp/pc/agent/myJSP-page.jsp</result>

Tuesday, August 27, 2013

Getting all the records from a table and displaying them in a DataGridView (Visual Basic.Net Version)

Written by: Biniam Asnake


Assuming you have already took the pleasure of creating a Visual Basic Windows Application and you have a database in SQL Server. For this case let’s call the database “Industry”


1st. Create app.config file (By right clicking on your project’s name in Solution Explorer)
2nd. Paste the following code


<connectionStrings>
   <add name="connectionString"
       connectionString="SERVER=(local);; DATABASE = Industry; Integrated Security=True;
Trusted_Connection= Yes;"
       providerName="System.Data.SqlClient" />
</connectionStrings>