Hi This like will help to get Microsoft sample codes:
http://code.msdn.microsoft.com/
.Net Video tutorial in Tamil
http://www.youtube.com/user/reach2arunprakash/
Thursday, December 8, 2011
Saturday, December 3, 2011
Bulk Upload in Sql server (using from OpenXML)
C# Code:
xml = " xml += " Element='SaveMyData' ";
xml += "EmpID='" + 1 + "' ";
xml += "EmpName='" + vijay + "' ";
xml += "EmpValue='" + 100 + "' />
";
IN SQL Server Stored Procedure:
CREATE PROCEDURE [dbo].[MyStoredProcedure]
@ActionType Varchar(20),
@XML text
AS
BEGIN
SET NOCOUNT ON
Declare @intRow int
Exec sp_xml_preparedocument @intRow Output, @xml
IF @ActionType ='Insert'
BEGIN
//Insert Query with Where condition
Insert into EmpEmployee (EmpID,EmpName,EmpValue)
Select xEmpID,xEmpName,xEmpValue
from OpenXML(@intRow,'/root/row[@Element="SaveMyData"]')
With
( xEmpID int '@EmpID', xEmpName varchar (50) '@EmpName', xEmpValue varchar (50) '@EmpValue', ) where xEmpID not in (select EmpID from EmpEmployee where EmpID=xEmpID,EmpName=xEmpName)
//Update Query with Where condition
Update EmpEmployee (EmpID=xEmpID,EmpName=xEmpName,EmpValue=xEmpValue)
from OpenXML(@intRow,'/root/row[@Element="SaveMyData"]') With ( xEmpID int '@EmpID', xEmpName varchar (50) '@EmpName', xEmpValue varchar (50) '@EmpValue', ) where EmpID=xEmpID and EmpName=xEmpName)
End
exec sp_xml_removedocument @intRow
END
xml = "
xml += "EmpID='" + 1 + "' ";
xml += "EmpName='" + vijay + "' ";
xml += "EmpValue='" + 100 + "' />
IN SQL Server Stored Procedure:
CREATE PROCEDURE [dbo].[MyStoredProcedure]
@ActionType Varchar(20),
@XML text
AS
BEGIN
SET NOCOUNT ON
Declare @intRow int
Exec sp_xml_preparedocument @intRow Output, @xml
IF @ActionType ='Insert'
BEGIN
//Insert Query with Where condition
Insert into EmpEmployee (EmpID,EmpName,EmpValue)
Select xEmpID,xEmpName,xEmpValue
from OpenXML(@intRow,'/root/row[@Element="SaveMyData"]')
With
//Update Query with Where condition
Update EmpEmployee (EmpID=xEmpID,EmpName=xEmpName,EmpValue=xEmpValue)
End
exec sp_xml_removedocument @intRow
END
Tuesday, November 22, 2011
Windows Application Error Handling & Check Allready Application Running
Windows Application Error Handling :
In the windows entire application or while opening an application if you get any exception means the below code will help you to capture the error log. The application error or exception handling you can identify the error message. This will help you to understand the problem in your windows application using C#.Net. The below code is start up point of the win application. The program.cs class only first fire in the application.
Check Allready Application Running:
string currPrsName = Process.GetCurrentProcess().ProcessName;
//Get the name of all processes having the
//same name as this process name
Process[] allProcessWithThisName
= Process.GetProcessesByName(currPrsName);
//if more than one process is running return true.
//which means already previous instance of the application
//is running
if (allProcessWithThisName.Length > 1)
{
MessageBox.Show("Application Already Running", "Test", MessageBoxButtons.OK);
Application.Exit();
}
else
{
Application.Run(new frmMain());
}
-->
In the windows entire application or while opening an application if you get any exception means the below code will help you to capture the error log. The application error or exception handling you can identify the error message. This will help you to understand the problem in your windows application using C#.Net. The below code is start up point of the win application. The program.cs class only first fire in the application.
Application Error Log
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace MyProject
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Control.CheckForIllegalCrossThreadCalls = true;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
//get the name of current process, i,e the process
//name of this current application
string currPrsName = Process.GetCurrentProcess().ProcessName;
//Get the name of all processes having the
//same name as this process name
Process[] allProcessWithThisName= Process.GetProcessesByName(currPrsName);
//if more than one process is running return true.
//which means already previous instance of the application
//is running
if (allProcessWithThisName.Length > 1)
{
MessageBox.Show("The Application Already Running", "MY APP", MessageBoxButtons.OK);
Application.Exit();
// allProcessWithThisName[0].Kill();
System.Diagnostics.Process.GetCurrentProcess().Kill();
}
else
{
frmMain mainForm = new frmMain(); //this takes ages
Application.Run(mainForm);
}
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject != null)
ErrorLog((Exception)e.ExceptionObject);
}
static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
if (e.Exception != null)
ErrorLog(e.Exception);
}
}
}
//Windows application Error Log
using System.IO;
public static void ErrorLog(string sMessage)
{
StreamWriter objSw = null;
try
{
string sFolderName = Application.StartupPath + @"\Logs\";
if (!Directory.Exists(sFolderName))
Directory.CreateDirectory(sFolderName);
string sFilePath = sFolderName + "Error.log";
objSw = new StreamWriter(sFilePath, true);
objSw.WriteLine(DateTime.Now.ToString() + " " + sMessage + Environment.NewLine);
}
catch (Exception ex)
{
Comman.ErrorLog("Error -" + ex.Message);
}
finally
{
if (objSw != null)
{
objSw.Flush();
objSw.Dispose();
}
}
}
Check Allready Application Running:
string currPrsName = Process.GetCurrentProcess().ProcessName;
//Get the name of all processes having the
//same name as this process name
Process[] allProcessWithThisName
= Process.GetProcessesByName(currPrsName);
//if more than one process is running return true.
//which means already previous instance of the application
//is running
if (allProcessWithThisName.Length > 1)
{
MessageBox.Show("Application Already Running", "Test", MessageBoxButtons.OK);
Application.Exit();
}
else
{
Application.Run(new frmMain());
}
-->
Friday, September 2, 2011
Adding Row in SQL SELECT Query statment
select 'Select All' as RallyNumber
union all
Select RallyNumber from MatchData
Tuesday, July 19, 2011
CSS for ASP.Net Button mouse over to change button colour
.forbuttons
{
border-style: none;
background-color: #0079C1;
color: #FFFFFF;
font-family: arial;
font-size: 13px;
font-weight: bold;
padding-top: 4px;
padding-bottom: 4px;
/* Mozilla: */
background: -moz-linear-gradient(top, #2bc4f3, #0095da);
/* Chrome, Safari:*/
background: -webkit-gradient(linear,
left top, left bottom, from(#2bc4f3), to(#0095da));
/* MSIE < 8 */
filter: progid:DXImageTransform.Microsoft.Gradient(
StartColorStr='#2bc4f3', EndColorStr='#0095da', GradientType=0);
/* IE 8*/
-ms-filter: progid:DXImageTransform.Microsoft.gradient(
startColorstr='#2bc4f3', endColorstr='#0095da');
}
.forbuttons:hover{
background: -moz-linear-gradient(top, #0095da, #2bc4f3);
/* Chrome, Safari:*/
background: -webkit-gradient(linear,
left top, left bottom, from(#0095da), to(#2bc4f3));
/* MSIE < 8 */
filter: progid:DXImageTransform.Microsoft.Gradient(
StartColorStr='#0095da', EndColorStr='#2bc4f3', GradientType=0);
/* IE 8*/
-ms-filter: progid:DXImageTransform.Microsoft.gradient(
startColorstr='#0095da', endColorstr='#2bc4f3');
}
.forbuttons:active{
background-color:#3399FF;
color:#FFF;
}
{
border-style: none;
background-color: #0079C1;
color: #FFFFFF;
font-family: arial;
font-size: 13px;
font-weight: bold;
padding-top: 4px;
padding-bottom: 4px;
/* Mozilla: */
background: -moz-linear-gradient(top, #2bc4f3, #0095da);
/* Chrome, Safari:*/
background: -webkit-gradient(linear,
left top, left bottom, from(#2bc4f3), to(#0095da));
/* MSIE < 8 */
filter: progid:DXImageTransform.Microsoft.Gradient(
StartColorStr='#2bc4f3', EndColorStr='#0095da', GradientType=0);
/* IE 8*/
-ms-filter: progid:DXImageTransform.Microsoft.gradient(
startColorstr='#2bc4f3', endColorstr='#0095da');
}
.forbuttons:hover{
background: -moz-linear-gradient(top, #0095da, #2bc4f3);
/* Chrome, Safari:*/
background: -webkit-gradient(linear,
left top, left bottom, from(#0095da), to(#2bc4f3));
/* MSIE < 8 */
filter: progid:DXImageTransform.Microsoft.Gradient(
StartColorStr='#0095da', EndColorStr='#2bc4f3', GradientType=0);
/* IE 8*/
-ms-filter: progid:DXImageTransform.Microsoft.gradient(
startColorstr='#0095da', endColorstr='#2bc4f3');
}
.forbuttons:active{
background-color:#3399FF;
color:#FFF;
}