Friday, December 29, 2017

How to create Roman Numerals function in SQL


CREATE Function [dbo].[GetRomanNo] ( @N as varchar(20) )
RETURNS VARCHAR(100)
AS
BEGIN
  DECLARE @s varchar(100), @r varchar(100), @i bigint, @p int, @d bigint
  SET @s = ''
  SET @r = 'IVXLCDM' -- Roman Symbols

  /* There is no roman symbol for 0, but I don't want to return an empty string */
 IF @n=0
  SET @s = '0'
 ELSE
 BEGIN
  SELECT @p = 1, @i = ABS(@n)
  WHILE(@p<=5)
  BEGIN
   SET @d = @i % 10
   SET @i = @i / 10
   SELECT @s = (CASE WHEN @d IN (0,1,2,3) THEN Replicate(SubString(@r,@p,1),@d) + @s
        WHEN @d IN (4) THEN SubString(@r,@p,2) + @s
        WHEN @d IN (5,6,7,8) THEN SubString(@r,@p+1,1) + Replicate(SubString(@r,@p,1),@d-5) + @s 
        WHEN @d IN (9) THEN SubString(@r,@p,1) + SubString(@r,@p+2,1) + @s END)
   SET @p = @p + 2
  END
 
  SET @s = Replicate('M',@i) + @s
 
  IF @n < 0
   SET @s = '-' + @s
  END

 RETURN @s
END 

Result

Thursday, December 28, 2017

How to use Foreach Loop in LINQ

public class Student
     {
            public int StudentID { get; set; }
            public string StudentName { get; set; }
        }

        public void GetStudent()
        {
            List<Student> obj = new List<Student>();

            Student objStudent1 = new Student();
            objStudent1.StudentID = 1;
            objStudent1.StudentName = "Test 1";
            obj.Add(objStudent1);

            Student objStudent2 = new Student();
            objStudent2.StudentID = 2;
            objStudent2.StudentName = "Test 1";
            obj.Add(objStudent2);

            obj.ForEach(c => {
                if (c.StudentID == 1)
                {
                    Console.Write("Student :" + c.StudentName);
                }
            });
        }

Saturday, December 23, 2017

How to display Notification in Notification Area of Taskbar in Windows Application

How to display Notification in Notification Area of Taskbar in Windows Application

DateTime Dates = Convert.ToDateTime("12/7/2012 6:09:11 PM");
TimeSpan diff = Dates - System.DateTime.Now;
notifyIcon1.Icon = SystemIcons.Exclamation;
notifyIcon1.BalloonTipTitle = "Days Remaning";
notifyIcon1.BalloonTipText = "Day : " + diff.Days.ToString();
notifyIcon1.BalloonTipIcon = ToolTipIcon.Error;
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(30000);

How to read & write file in isolation storage in c#

How to read & write file in isolation storage in c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.IO.IsolatedStorage;
using System.Diagnostics;

namespace Program
{
        //Variable
        string FullLine;
        const string ISOLATED_FILE_NAME = "Setting.txt";
        IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);

        private void ISOStorageUse_Load(object sender, EventArgs e)
        {
            cbYesNo.Text = "No";
            ddlStandard.SelectedIndex = 0;
           
            #region Get Data
            IsolatedStorageFileStream iStream = new IsolatedStorageFileStream(ISOLATED_FILE_NAME, FileMode.OpenOrCreate, isoStore);
            StreamReader reader = new StreamReader(iStream);
            FullLine = reader.ReadToEnd();
            reader.Close();
            #endregion Get Data

            #region Apply Value
            string SplitPart = FullLine.Replace("\r\n", ",");
            string[] Parts = SplitPart.Split(',');

            if (SplitPart == "") return;
            dtpDate.Value = Convert.ToDateTime(Parts[0]);
            tbName.Text = Parts[1];
            ddlStandard.SelectedIndex = Convert.ToInt32(Parts[2]);
            cbYesNo.Checked = Convert.ToBoolean(Parts[3]);
            #endregion Apply Value
        }

       // Form Closing Event
       private void ISOStorageUse_FormClosing(object sender, FormClosingEventArgs e)
       {
            // Write some text into the file in isolated storage.
            IsolatedStorageFileStream oStream = new IsolatedStorageFileStream(ISOLATED_FILE_NAME, FileMode.OpenOrCreate, isoStore);
            StreamWriter writer = new StreamWriter(oStream);
            writer.WriteLine(dtpDate.Value);
            writer.WriteLine(tbName.Text);
            writer.WriteLine(ddlStandard.SelectedIndex);
            writer.WriteLine(cbYesNo.Checked);
            writer.Close();
       } 
}

How to use String Builder in C#

How to use String Builder in C#


using System;
using System.Text;

class Program
{
    static void Main()
    {
       StringBuilder builder = new StringBuilder();
       // Append to StringBuilder.
       for (int i = 0; i < 10; i++)
       {
            builder.Append(i).Append(" ");
       }
       Console.WriteLine(builder);
    }
}

IF / Else IF Condition in MSSQL

IF / Else IF Condition in MSSQL


-- HOW TO USE IF / ELSE IF CONDITION IN SQL

DECLARE @ColorCode Int 

SET @ColorCode = 2

IF (@ColorCode = 1)
BEGIN
 SELECT 'RED' AS ColorName
END
IF (@ColorCode = 2)
BEGIN
 SELECT 'GREEN' AS ColorName
END
IF (@ColorCode = 3)
BEGIN
 SELECT 'BLUE' AS ColorName
END



Thursday, December 21, 2017

How to change Schema Name in SQL

Below Query for change you table schema name from eg. dbo. to test.

ALTER SCHEMA YourSchemaName TRANSFER dbo.YourTableName

-- it will change your schema name from "dbo" to "YourSchemaName"

How to create KBC game in c# desktop application

Source Code

Click here Download KBC Game Source Code

Exe

Click here Download KB Game exe


First Create One Form like forma name is Dashboard.

Then Drag and Drop control and design form.see image Dashboard design layout.


See Out-Put in KBC Game:


1) Audience Poll Screen short :




2) KBC Game Use 50-50 Option



3) KBC Game your answer is wrong then display You Lose Game See Image


4) KBC Game Your all Answer is Currect then you are win see display image











How to get TOP n Records from Azure document DB

How to get TOP n Records from Azure document DB

=>

           Query : SELECT TOP 1 * FROM c

            Result : Your Database Record


How to get record count in Azure DocumentDb (Microsoft Document DB)

How to get record count from cosmos DB (Microsoft Document DB)


=>    Query : SELECT COUNT(1) FROM c  WHERE c.City = "A"

         Result : [  {  "$1": 15 } ]

Wednesday, December 20, 2017

How to find all triggers on a table in sql server ?

How to find all triggers on a table in sql server ?

=>

SELECT NAME, PARENT_ID, CREATE_DATE, MODIFY_DATE, S_INSTEAD_OF_TRIGGER  
FROM SYS.TRIGGERS  WHERE TYPE = 'TR';

     I am create one trigger  in sql server.trigger name like test trigger create then run above query to find your result.display all trigger in database and all table see output.

Output:-


Saturday, December 9, 2017

How to get SQL database connection string in 5 simple steps

Step 1 : First Open Server Explorer in your Visual Studio IDE


Step 2 : Now click on + button for open connection dialog


Step 3 : now paste your Server Name for get database list



Step 4 : when you paste your server name 1 Dropdown list is open for select database now select your database


Step 5 : now click on Advance button and get your connection string



Happy developing....

How to use case when in sql query

In this  example first declare 1 variable for store value you can also use case when in SQL query

DECLARE @Type Int

--  Set value in declared variable
SET @Type = 1

-- now use case when like this normally it's just like if & else if condition

SELECT (CASE
        WHEN @Type = 1 THEN 'Red'           [if type = 1 { 'red' } ]
        WHEN @Type = 2 THEN 'Green'
        WHEN @Type = 3 THEN 'Blue'
        ELSE 'No Colors' END)

SQL Datatype

SQL DataType

1. BigInt
    From C# side it stores Int64 Value
    MaxValue = 9223372036854775807
    MinValue = -9223372036854775808


2. Bit
    C# : Store Bool Value Like True or False 
 
3. DateTime
    C# : Store Date Time

4. Float
    C# : Store Float Value
    MaxValue = 3.40282e+038f
    MinValue = -3.40282e+038f


5. Int
    C# : Store Int32 Value
    MaxValue = 2147483647
    MinValue = -2147483648


6. Numeric(18,0)
    SQL store value like 18 digits with 2 or more decimal place
    e.g. 12.00


7. Nvarchar(50)
    SQL store Text & unique code value with limited size

8. Nvarchar(MAX)
    SQL store Text & unique code value no limit for store data

9. Varchar(50)
    SQL store only text Varchar datatype do not support unique code value

10. Varchar(MAX)
    SQL store only text Varchar datatype do not support unique code value

11. Uniqueidentifier
    SQL store Numeric, Characters, and - with the lenth of 36 characters
    Uniqueidentifier do not repeat it generate unique value every time
    C# : store GUID value

How to Install SQL Sever 2008 R2?

How to Install SQL Sever 2008 R2?

=>   Sql Server Installation Step Follow Bellow : - 

1) First of all download sql server management studio 2008 then click setup see image 


2) Second step display installation dialog box see image


3) Third step display SQL Server Installation Center Then select "New Installation or add features to an existing installation" Text click see image



4) Then display setup support  rules dialog box see image


5) This step is display license terms then by default two checkbox is unselected display see image


6) This step is select two checkbox then enable next button see image


7) This step is display feature selection then click next button see image


8) This step is display error reporting dialog then click next button see image



9) This step is display complete installation see image 


10) This step is display your setup is ready to user create new database see image



How to setup in visual studio 2013,2017 ?

How to setup in visual studio 2013,2017

                                                                   This article is explain how to setup in visual studio 2013.First of all download visual studio 2013 setup then follow step below.

1) First of all setup double click 


2) Then open visual studio 2013 dialog box then click continue button show below image.


3) Third step is by default path is set "C:\Program Files\Microsoft Visual Studio 12.0". it can change path and set new path otherwise default path store all file and setup data.

                                         Third step display "I Agree to the License Terms and Privacy Policy"
Checkbox by default un-selected display then select checkbox to display Next button.see image



4) Then Click Next Button see Image.


5) Fifth step display "Optional features to install" by default all selected. then click Install Button.See image



6) Six step is display progress bar in i think 40 minute process to install visual studio 2013 data.waiting in 40 minutes see image

7) Congratulation your setup is completed install and display dialog see image

8) Then click "LAUNCH" text 

9) Nine step to display  "Welcome Sign in to Visual Studio." then click "Not now,Maybe later " text.see image


10) This step is choose your color theme.there are three theme display
  1.  Blue
  2. Dark
  3. Light
Select a Blue color theme then click Start Visual Studio. see image


11) This step is display waiting few minute see image


12) Finally all process is finish display visual studio 2013 dialog.your are create own web application,Software etc.see image

Serial Port with Efficient Data reading in C#



  • I am  not good at writing but below is few from my collection.
  • Declare the Port variable globally in a form.


    1. SerialPort Port;   
    2. string PORT_NUMBER = "YOUR PORT NUMBER" ;   
  • Set the port properties in Form load. 

try  
{  
   Port = new SerialPort("COM" + PORT_NUMBER.ToString());  
   Port.BaudRate = 115200;  
   Port.DataBits = 8;  
   Port.Parity = Parity.None;  
   Port.StopBits = StopBits.One;  
   Port.Handshake = Handshake.None;  
   Port.DtrEnable = true;  
   Port.NewLine = Environment.NewLine;  
   Port.ReceivedBytesThreshold = 1024;  
   Port.Open();  
  
}  
catch (Exception ex)  
{  
   MessageBox.Show("Error accessing port." + Environment.NewLine + ex.Message, "Port Error!!!", MessageBoxButtons.OK);  
   Port.Dispose();  
   Application.Exit();  
}   
  
  • Above is the basic procedure and easy to understand.
  • Now create following function which will be helpful to read data from serial port simultaneously. 

private void ReadEvent()  
{
byte[] buffer = new byte[2000];  
Action kickoffRead = null;  
kickoffRead = (Action)(() => Port.BaseStream.BeginRead(buffer, 0, buffer.Length, delegate(IAsyncResult ar)  
{  
    try  
    {  
        int count = Port.BaseStream.EndRead(ar);  
        byte[] dst = new byte[count];  
        Buffer.BlockCopy(buffer, 0, dst, 0, count);  
        RaiseAppSerialDataEvent(dst);  
    }  
    catch (Exception exception)  
    {  
        MessageBox.Show(ERROR == > " + exception.ToString());    
    }  
    kickoffRead();  
}, null)); kickoffRead();  
}  

    //To decode the received data from the port.   
    private void RaiseAppSerialDataEvent(byte[] Data)  
    {  
        string Result = Encoding.Default.GetString(Data);  
         TextBox1.Invoke((Action)delegate   
    {  
       TextBox1.Text=Result; TextBox1.Refresh();   
    });   
    }  



    It will keep assigning same event when data received.

    Port.BaseStream.BeginRead 

    Never fails and will give you each and every bit from the Port.
    To invoke this you need to Call Port.WriteLine("AT COMMAND");
    Hope it helps someone who is stuck with ports.
     

    Sunday, December 3, 2017

    How to pass and get value in query string asp.net

    One page to another page pass value in query string :

    First pass value in query string: 

    Response.Redirect("QueryString.aspx?QueryString=" + txtQueryString.Text);

    Get QuerySting value in Asp.net:
     QueryString.Text = Request.QueryString["QueryString"];