Saturday, December 22, 2012

How to Clear DataGridView in C# .net

      In somettimes the following Code
Shows Problem Clearing Data from datagridView


dataGridView1.Rows.Clear()

 Then The Code Below Will Be Helpfull Clearing Data from DataGridView in C#.Net


 ((DataTable)dataGridView1.DataSource).Rows.Clear();

Wednesday, December 5, 2012

How to make a Textbox to accept only digit in c#.net

 


 In the Keypress Event of a textBox just write the following Code

then it will get only number and no letter

   private void txtSalary_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            e.Handled = !(char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == (char)Keys.Back);
        }

Sunday, November 18, 2012

Data Table Filtering In C#.Net


 Filtering  Datatable "dtItem" copy the table to "dt2"

 DataTable dtItem=new DataTable();
 DataTable dt2=new DataTable();

 DataRow[] drs = dtItem.Select("CategoryID =1 ");
            //make a new "results" datatable via clone to keep structure
            dt2 = dtItem.Clone();
            //Import the Rows
            foreach (DataRow d in drs)
            {
                dt2.ImportRow(d);
            }

            foreach (DataRow dr in dt2.Rows)
            {
              ItemNamecomboBox2.Items.Add(dr[1].ToString());
            }

Wednesday, November 14, 2012

How to Write and Call Scaler Function in SQL Server 2008



 At First Create A Scaler Function
Click '+' Sign near the Database in the Object Explorer
Click '+'  Programmability
Click '+'  Functions
Right Click on 'Scaler-Valued Functions'
New Scaler-Valued Functions

Now Write the Following Function
Create FUNCTION fncNEwID (@Param Varchar(15))
RETURNS int
AS
BEGIN
Declare @Retval int
Select @Retval=0,@Param=Upper(@Param)

if(@Param ='CATEGORY')
Begin
Select @Retval=Isnull(Max(CategoryId),0)+1
from Category
End
Return @Retval
END
GO

Now Call The Function
DECLARE @MyDecimalVar int
EXEC @MyDecimalVar = dbo.fncNEwID 'CUSTOMER'
SELECT @MyDecimalVar
GO


Friday, November 9, 2012

Step by Step Of Creating a Windows Service in C#.NET

Step by Step Of Creating a Windows Service in  C#.NET

Suppose We are going to create a windows service in C# and it's name is (Secondservice) and it write a text file in every 10 second

Start:
Go to: All Programme---->Microsoft Visual Studio---->Create---->new---->Windows---->WindowsService--->ok


SolutionExplorer(Right Side of the Widow)--->Right Button Click--->Rename  Now rename it as SecondService

At middle part of the window click on the click here to switch to code view  Write the following code:



 Now go to the SecondService.cs(Design) Page:
n the Blank part  Click Right----->Add Installer then two new item is added SeconService and ServiceprocessInstaller  
 Now Putting Mouse on SecondSErvice RightButton--->Properties 
 Write as following Picture shows




Now Putting Mouse on  ServiceprocessInstaller   RightButton--->Properties
Write as following Picture shows





After this go to solution Explorer Right button Click----->Build
After Successfully Building 


Go to Source locaton of the Project      SeconServie----->bin----->Debug

Now Copy the source location path   Suppose( G:\c-sharp\SecondService\SecondService\bin\Debug  )

Now go to AllProgramme--->Microsoft Visual Studio---->Visual Studio Tool--->visual studio 2008 command promt 





 After that Paste source location you copied earlier
then Write installutil SecondService.exe  press Enter
After Successfull installation

 Go to All programme-------->Computer------>RightClick----->Manage
Click on Service item as indicated in the following picture 


 Now At the Right Side We can see there are a service named SeconService
the Click Right button on SecondService item --------->Start