Friday, 21 February 2014

Character arrays in T-SQL

--Inputs
declare @x varchar(100)
set @x = 'WORDS'
--Table of letters (like an array)
select substring(@x, number, 1) as v
from master.dbo.spt_values where number between 1 and len(@x) group by number order by number
--Example manipulation
declare @y varchar(100)
select @y = isnull(@y, '') + char(ascii(substring(@x, number, 1))+1)
from master.dbo.spt_values where number between 1 and len(@x) group by number order by number
select @x as 'Original', @y as 'Manipulated (shifted by 1)'
/*Results
v   
----
W
O
R
D
S
Original         Manipulated (shifted by 1)  
---------------- -----------------------------
WORDS            XPSET
*/

Sunday, 29 September 2013

How to write C# Program to Print Star Triangle

How to write C# Program to Print Star Triangle

This program will help beginners to write their lab assignment. You can take the logic from below given code. There is 3 loops
First loop is for printing limit and second loop is for space , third loop is for  printing star.
image
C# Program to print star triangle:
using System;
namespace MyApp
{
    class triangle_class
    {
        static void Main(string[] args)
        {
            int number = 12;
            for (int i = 1; i <= number; i++)
            {
                for (int j = 1; j <= number - i; j++)
                    Console.Write(" ");
                for (int k = 1; k <= i; k++)
                    Console.Write(" *");
                Console.WriteLine("");
            }                      
            Console.ReadLine();
        }
    }
}

Thursday, 30 May 2013

How to get valuemember of display member in checkedlistbox c#

See more: C#
public void FillCheckedListBox1party()
            {
               try
                  {
                        if (con.State == ConnectionState.Closed)
                        {
                              con.Open();
                        }

                        string commandString = "SELECT NAME ,AC_CODE FROM AccountM where compcode='" + Compcls.Gcomp_cd + "'";
                 
                        DataTable accTable = new DataTable();
                        SqlCommand cmd = new SqlCommand(commandString, con);
                        SqlDataAdapter adpObj = new SqlDataAdapter(cmd);
                        accTable.TableName = "tbl";
                        adpObj.Fill(accTable);
                        con.Close();
                        checkedListBox1.DataSource = accTable;
                        checkedListBox1.ValueMember = "AC_CODE";
                        checkedListBox1.DisplayMember ="NAME";
                        checkedListBox1.BindingContext = new BindingContext();
                        // myChkListBox.BindingContext = new BindingContext();
                  }
                  catch (Exception ex)
                  {

                        throw ex;
                  }
                  finally
                  {
                        con.Close();
                  }
            }
 =================================>
 StringBuilder sb = new StringBuilder();
            for (int i = 0; i < ChkListBox.CheckedItems.Count; i++)
            {
                if (ChkListBox.CheckedItems.Count > 0)
                {
                    DataRow row;
                    row = ((DataRowView)this.ChkListBox.CheckedItems[i]).Row;
                   var val = (row[this.ChkListBox.ValueMember]).ToString();
                    row = null;

                    sb.AppendFormat("{0}, ", val.ToString());
                }
            }
            MessageBox.Show(sb.ToString().TrimEnd(',', ' '));







===================>

Ref: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/405e0178-bfb2-494e-ba80-f06f89038ac0

Saturday, 18 May 2013


Step1:

class Employee
    {
        public string ID{ get; set; }
        public string Name{ get; set; }
    }
Step2: Place a checkedListBox on Form.
Step3:
public void bind()
        {
            List<Employee> lis = new List<Employee>();
            for (int i = 0; i < 10; i++)
            {
                Employee obj = new Employee();
                obj.ID = i.ToString();
                obj.Name = "Name:" + i;
                lis.Add(obj);
            }
            checkedListBox1.DataSource = lis.ToList<Employee>();
            checkedListBox1.DisplayMember = "Name";
            checkedListBox1.ValueMember = "ID";

        }

Above method call in Form_Load.

Find the Item checked or not.
checkedListBox1.SetItemChecked(5, true);
Find the checkedList Items:
  foreach (var item in checkedListBox1.CheckedItems)
            {
                var Emp = (Employee)item;
                MessageBox.Show(Emp.ID + ": " + Emp.Name);
            }

Thursday, 16 May 2013

Winform : How to Databind CheckedListBox if it is missing DataSource

Winform : How toDatabind CheckedListBox if it is missing DataSource


When you decide to use CheckedListBox Control, you might expect to useDisplayMember, ValueMember or DataSource property like you do for example with ListBox, but you will discover that the Intellisense is not showing those properties at all.
The good news is that even though Intellisense will not show them, the code will still compile when you type those properties by hand.
Now you might think problem solved. Well not exactly.
Microsoft is not recommending this approach. According to them, Data Binding is not supported on CheckedListBox but since the above properties are inherited from a base class, they can not be removed, so the Microsoft just hid them. 
So keep this in mind if you decide to use those properties on  CheckedListBox

How do you fill the control with items without using DataSource property?

One solution of course is to use Items.Add method to add individual item. If you already have an array or a list that contains items, you then use foreach loop and add every item with Items.Add like this:
string[] IceCreamFlavors = {"Banana", "Chocolate", "Pistachio", "Strawberry", "Vanilla"};
foreach (var item in IceCreamFlavors)
{
  checkedListBox1.Items.Add(item);
}
But there is simpler way to add items from array or a List by using Items.AddRangemethod instead like this:
checkedListBox1.Items.AddRange(IceCreamFlavors);
If you want to add items from a List, just use ToArray method:
checkedListBox1.Items.AddRange(myList.ToArray());
I hope you found this article useful. Feel free to drop a comment or connect with this blog on the social networks.

Friday, 5 April 2013

Dot Net Framework 3.5 Not Installing on Windows 8? Fix it Now!





You may face a common problem while using Windows 8. Microsoft .Net Framework 3.5 is not installed with Windows 8. And several programs may ask you install this. And you can't install this from your PC. It will ask you to connect to the net and use Windows Update. 

By default Windows 8 comes with .Net Framework 4.5 and it doesn't include 3.5. When you try to install .Net 3.5 that you previously downloaded from web the you will see the following message. 




And you will get the same message while installing some some programs that is developed using .Net 3.5 platform. And you will not able to run those programs on your PC! This is a very bad job by Microsoft. A great trouble for Windows 8 users. 

But today you will get the solution. You've install this using command line. I mean you have to use Command Prompt. And surprisingly you Windows 8 DVD includes the .Net Framework 3.5! 

Method 1 (Offline Installation using cmd):
  1. Enter your Windows 8 Installation Disk on DVD Drive.
  2. Now run Command Prompt as Administrator. (Hint: Start > Type cmd > Now right click on Command Prompt and hit on Run as Administrator from the bottom)
  3. Now copy the following command and paste it in the command prompt window. Or type the following line in command prompt. Press Enter (To paste the command in command prompt, click the right button of mouse and select paste)
  4. Now .Net Framework will be installed within few minutes. 
DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /LimitAccess /Source:h:\sources\sxs


Remember: h is the drive letter of DVD drive. Change it with your DVD drive letter. 


Method 2 (Online Method using Windows Update): 

If you follow all the instructions of method 1 you will be able to install .net 3.5 properly. But if there is any problem for example- you don't have DVD drive, or your Windows DVD doesn't contain it then you can install it directly from Windows Update option. More or less you've to download 200 MB data from internet. 

Follow the instruction below: 
Control Panel > Programs and Features > Turn Windows Features on or off > Mark the option .NET Framework 3.5 (includes .NET 2.0 and 3.0) > OK. 
Now you will see a window like the image above. Hit on Install This Feature. And make sure you're connected to the net. That's it.  


Installing a Windows language pack on Windows 8 before installing the .NET Framework 3.5 will cause the .NET Framework 3.5 installation to fail. Install the .NET Framework 3.5 before installing any Windows language packs.

Monday, 1 April 2013

System.Security.SecurityException: Request for the permission of type ‘System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.


Server Error in ‘/’ Application.


Security Exception

Description:

The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type ‘System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.

Source Error:An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:
[SecurityException: Request for the permission of type
'System.Web.AspNetHostingPermission, System,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.]
   System.Reflection.Assembly._GetType(String name,
Boolean throwOnError, Boolean ignoreCase) +0
   System.Web.UI.Util.GetTypeFromAssemblies(ICollection
assemblies, String typeName, Boolean ignoreCase) +201
   System.Web.UI.TemplateParser.GetType(String typeName,
Boolean ignoreCase, Boolean throwOnError) +323
   System.Web.UI.TemplateParser.ProcessInheritsAttribute(String
baseTypeName, String codeFileBaseTypeName,
String src, Assembly assembly) +10891548
   System.Web.UI.TemplateParser.PostProcessMainDirectiveAttributes
(IDictionary parseData) +365
Cause
The files were downloaded from the internet or an untrusted source.  Your computer/server are blocking them to help in protecting your computer.
Solution:


Right click on each file that you download and choose properties and Unblock.

image
Add the following to the system.web section of the web.config file.
Validate you have the correct .NET code base. You may have 4.0 code that is running as 2.0