C#
In a console application, output will be show in command prompt.
And i t will generate an .exe file for the user to execute the application.
Some users may need to read a text file from specific directory in the application.
Generally will using ConfigurationManager.AppSettings.Get("Directory");
To run the console application, user require the compile files(.exe, .config and other .dll or text file).
Source file is not required after compilation.
However, if compile file is moved to some others directory before execution, user are required to edit the path name of text file in .config file. If the compile file will be executed as portable(in different computer), user might need to change the path name manualy.
Here is an easy way to get the execute path name.
//add System.windows.Form Reference
{
String a = "";
a = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath ) + "\\file.txt";
Console.WriteLine(a);
//See the output..
}
Thursday, March 27, 2008
Wednesday, March 26, 2008
SQL Select Case Statment
The SQL CASE statement has WHEN, THEN, and ELSE clauses along with an END terminator. The syntax is:
CASE [expression]
WHEN [value | Boolean expression] THEN [return value]
[ELSE [return value]]
END
The [expression] is optional and contains a table column or a variable. When you specify [expression] directly after the CASE, you must populate the [value] parameter in the WHEN clause:
DECLARE @TestVal int
SET @TestVal = 3
SELECT
CASE @TestVal
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END
Here is an example:-
Table Name: tbl_User
---------------
Name | Age |
---------------
User1 | 8 |
User2 | 10 |
User3 | 35 |
User4 | 50 |
---------------
SELECT
CASE Age
WHEN <=12 THEN 'Child'
WHEN <=18 THEN 'Teen'
ELSE 'Adult'
END AS 'Group'
FROM tbl_User
WHERE Name = 'User1'
Output:-
-------
Group |
-------
Child |
-------
CASE [expression]
WHEN [value | Boolean expression] THEN [return value]
[ELSE [return value]]
END
The [expression] is optional and contains a table column or a variable. When you specify [expression] directly after the CASE, you must populate the [value] parameter in the WHEN clause:
DECLARE @TestVal int
SET @TestVal = 3
SELECT
CASE @TestVal
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END
Here is an example:-
Table Name: tbl_User
---------------
Name | Age |
---------------
User1 | 8 |
User2 | 10 |
User3 | 35 |
User4 | 50 |
---------------
SELECT
CASE Age
WHEN <=12 THEN 'Child'
WHEN <=18 THEN 'Teen'
ELSE 'Adult'
END AS 'Group'
FROM tbl_User
WHERE Name = 'User1'
Output:-
-------
Group |
-------
Child |
-------
SQL Select Case Statment
The SQL CASE statement has WHEN, THEN, and ELSE clauses along with an END terminator. The syntax is:
CASE [expression]
WHEN [value | Boolean expression] THEN [return value]
[ELSE [return value]]
END
The [expression] is optional and contains a table column or a variable. When you specify [expression] directly after the CASE, you must populate the [value] parameter in the WHEN clause:
DECLARE @TestVal int
SET @TestVal = 3
SELECT
CASE @TestVal
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END
Here is an example:-
Table Name: tbl_User
---------------
Name | Age |
---------------
User1 | 8 |
User2 | 10 |
User3 | 35 |
User4 | 50 |
---------------
SELECT
CASE Age
WHEN <=12 THEN 'Child'
WHEN <=18 THEN 'Teen'
ELSE 'Adult'
END AS 'Group'
FROM tbl_User
WHERE Name = 'User1'
Output:-
-------
Group |
-------
Child |
-------
CASE [expression]
WHEN [value | Boolean expression] THEN [return value]
[ELSE [return value]]
END
The [expression] is optional and contains a table column or a variable. When you specify [expression] directly after the CASE, you must populate the [value] parameter in the WHEN clause:
DECLARE @TestVal int
SET @TestVal = 3
SELECT
CASE @TestVal
WHEN 1 THEN 'First'
WHEN 2 THEN 'Second'
WHEN 3 THEN 'Third'
ELSE 'Other'
END
Here is an example:-
Table Name: tbl_User
---------------
Name | Age |
---------------
User1 | 8 |
User2 | 10 |
User3 | 35 |
User4 | 50 |
---------------
SELECT
CASE Age
WHEN <=12 THEN 'Child'
WHEN <=18 THEN 'Teen'
ELSE 'Adult'
END AS 'Group'
FROM tbl_User
WHERE Name = 'User1'
Output:-
-------
Group |
-------
Child |
-------
Thursday, March 13, 2008
For Loop Java C# VB
For loop is a statement that allow code to be repeatedly execute.
Code will keep on looping in the loop until it reach the condition that break it out.
Java coding is very similar with C# coding...
However both of them are different language...
Java
for(int i=0; i<= 10 ; i++){
System.out.print(i + " ");
}
//output : 0 1 2 3 4 5 6 7 8 9 10
c#
for(int=0; i<=10 ; i++){
Console.write(i + " ");
}
//output : 0 1 2 3 4 5 6 7 8 9 10
VB
dim i as integer
for i = 0 to 10
msgbox(i)
next
//output :"A message box will prompt wif the value of": 0 1 2 3 4 5 6 7 8 9 10
Code will keep on looping in the loop until it reach the condition that break it out.
Java coding is very similar with C# coding...
However both of them are different language...
Java
for(int i=0; i<= 10 ; i++){
System.out.print(i + " ");
}
//output : 0 1 2 3 4 5 6 7 8 9 10
c#
for(int=0; i<=10 ; i++){
Console.write(i + " ");
}
//output : 0 1 2 3 4 5 6 7 8 9 10
VB
dim i as integer
for i = 0 to 10
msgbox(i)
next
//output :"A message box will prompt wif the value of": 0 1 2 3 4 5 6 7 8 9 10
Tuesday, March 11, 2008
JAVA - jsp to Excel - jxl API
jxl is a library that support jsp to export data from jsp to excel.
You need to import the jxl jar file into ur own project library..
------------------------------------------------------------------------------------
//Import the class
import javax.servlet.http.*;
import java.util.*;
import java.lang.Integer;
import java.io.File;
import jxl.Workbook;
import jxl.write.WritableWorkbook;
import jxl.write.WritableSheet;
import jxl.write.WritableFont;
import jxl.write.WritableCellFormat;
import jxl.write.Label;
import jxl.format.Alignment;
import jxl.format.VerticalAlignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
//generate output data type == Excel
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=StudentReport.csv");
//create a Excel file
WritableWorkbook w = Workbook.createWorkbook(response.getOutputStream());
//create Excel sheet (sheet's name, sequence of sheet)
WritableSheet sh = w.createSheet("ClassSize", 0);
//declare font type
WritableFont boldFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);
//declare font type and color
WritableFont redFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD);
redFont.setColour(Colour.RED);
//declare font alignment
WritableCellFormat wcf_red = new WritableCellFormat(redFont);
wcf_red.setAlignment(Alignment.LEFT);
WritableCellFormat wcf_left = new WritableCellFormat();
wcf_left.setAlignment(Alignment.LEFT);
int excelColCount = 1;
int excelRowCount = 8;
// add and write into cells
sh.addCell(new Label(0, 1, "Institution:",new WritableCellFormat(boldFont)));
sh.addCell(new Label(1, 1, "School Of Multimedia Information Technology"));
sh.addCell(new Label(0,2,"Creation Date : " ,new WritableCellFormat(boldFont)));
sh.addCell(new Label(1,2,getDayOfCreation() ));
sh.addCell(new Label(0,3,""));
sh.addCell(new Label(0,4, "Student : ",new WritableCellFormat(boldFont)));
sh.addCell(new Label(1,4, student));
sh.addCell(new Label(0,5,""));
sh.addCell(new Label(0,6,"Year/Semester :",new WritableCellFormat(boldFont)));
sh.addCell(new Label(1,6,year + "/" + sem));
--------------------------------------------------------------------------------
You need to import the jxl jar file into ur own project library..
------------------------------------------------------------------------------------
//Import the class
import javax.servlet.http.*;
import java.util.*;
import java.lang.Integer;
import java.io.File;
import jxl.Workbook;
import jxl.write.WritableWorkbook;
import jxl.write.WritableSheet;
import jxl.write.WritableFont;
import jxl.write.WritableCellFormat;
import jxl.write.Label;
import jxl.format.Alignment;
import jxl.format.VerticalAlignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
//generate output data type == Excel
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=StudentReport.csv");
//create a Excel file
WritableWorkbook w = Workbook.createWorkbook(response.getOutputStream());
//create Excel sheet (sheet's name, sequence of sheet)
WritableSheet sh = w.createSheet("ClassSize", 0);
//declare font type
WritableFont boldFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);
//declare font type and color
WritableFont redFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD);
redFont.setColour(Colour.RED);
//declare font alignment
WritableCellFormat wcf_red = new WritableCellFormat(redFont);
wcf_red.setAlignment(Alignment.LEFT);
WritableCellFormat wcf_left = new WritableCellFormat();
wcf_left.setAlignment(Alignment.LEFT);
int excelColCount = 1;
int excelRowCount = 8;
// add and write into cells
sh.addCell(new Label(0, 1, "Institution:",new WritableCellFormat(boldFont)));
sh.addCell(new Label(1, 1, "School Of Multimedia Information Technology"));
sh.addCell(new Label(0,2,"Creation Date : " ,new WritableCellFormat(boldFont)));
sh.addCell(new Label(1,2,getDayOfCreation() ));
sh.addCell(new Label(0,3,""));
sh.addCell(new Label(0,4, "Student : ",new WritableCellFormat(boldFont)));
sh.addCell(new Label(1,4, student));
sh.addCell(new Label(0,5,""));
sh.addCell(new Label(0,6,"Year/Semester :",new WritableCellFormat(boldFont)));
sh.addCell(new Label(1,6,year + "/" + sem));
--------------------------------------------------------------------------------
import, using , imports
To use some built function/class in Integrated Development Environment (IDE) such as Visual Studio, Netbeans, JBuilder, Eclipse, Textpad
Developer require to import the classes before coding..
Developer need to import those classes differently in different kind of language.
JAVA-
imports java.util.*;
imports java.io.*;
Java is using 'imports' to implements the classes.
* is refering to the all functionality in the class.
C#-
using System.Data;
using System.IO;
C# is using 'using' to implements the classes.
VB-
Imports System.Web.UI
Imports System.Web.UI.WebControls
VB is using 'Imports' to implements the classes.
Developer require to import the classes before coding..
Developer need to import those classes differently in different kind of language.
JAVA-
imports java.util.*;
imports java.io.*;
Java is using 'imports' to implements the classes.
* is refering to the all functionality in the class.
C#-
using System.Data;
using System.IO;
C# is using 'using' to implements the classes.
VB-
Imports System.Web.UI
Imports System.Web.UI.WebControls
VB is using 'Imports' to implements the classes.
Subscribe to:
Comments (Atom)