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 useDisplayMemberValueMember 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



Sunday 17 March 2013

Error occurred in deployment step 'Retract Solution': Cannot start service SPUserCodeV4 on computer

Error occurred in deployment step 'Retract Solution': Cannot start service SPUserCodeV4 on computer

Title: SharePoint 2010 Error occurred in deployment step 'Retract Solution': Cannot start service SPUserCodeV4 on computer

Details: Building Sandboxed Solutions on SharePoint 2010 using Visual Studio 2010 Beta and encountered the error? Then make sure that the service Microsoft SharePoint Foundation User Code Service ( CA > System Settings > Services on Server ) is Started.

Thursday 14 March 2013

Creating Full Text Index in SQL Server


Introduction

In this article we will see how to create a full text search index for SQL Server database for effective search. In so many cases we need to provide the search facility in our application. To provide searching facility within our local database we can use the greater feature provided by Microsoft SQL Server i.e. full text index.

Background

When we want to use the full text index service we need to start the service first else it will raise the errors. So let's start with how to start the service and use the Full text index step by step.

Step 1

Open SQL Server and create a new database with the following table for eg. Tbl_Search but keep in mind that the full text index only works on primary key or unique key containing tables.

Create Table Tbl_Search
(
Id Int Primary Key Identity(1,1),
Title Varchar(500),
[Desc]Varchar(max)
)

Insert some rows in the created table.

Step 2

Now we will create full text index on our database and table for providing search in table. So create the Full Text Catalog on our database by using following query.

CREATE FULLTEXT CATALOG FTSearch

In the query above we have created FullText Catalog with the name FTSearch.

Step 3

Now we will create full text index on our table Tbl_Search but for that we require the unique key id or primary key id so find the id of unique or primary key by using following command.

SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS

This command will display the all constraint names on tables present in our database from the output. Copy the Tbl_Search constraint name for creating a full text index on TblSearch.

CREATE FULLTEXT INDEX ON Tbl_Search


(Title, [Desc] LANGUAGE 1033)
KEY INDEX PK__Tbl_Sear__3214EC0700551192
ON FTSearch

In the above statement you can see we are creating a FullText Index on table name with a parameter; this parameter is nothing but the column name of the table on which we want to create the full text index and language 1033 denotes the language English.

Step 4

Now it's time to search the records in a specified indexed table. For that we can write the queries like below.

Select * from Tbl_Search Where Contains(Title,'Asp.Net')
Select * from Tbl_Search Where Freetext([Desc],'Asp.Net')

In the preceding queries you can see we have given a where clause with column name which is the column we want to search and what we want to search. The preceding queries retrive the rows of a table which contain ASP.Net in title column and the second query will retrieve the rows of ASP.Net in the desc column.

In some cases your queries gives an error like fdhost cannot be started. That means your FullTextIndex Service is not started; for that you have to first start the Demon Launcher for FullTextIndex service.

Step 5

For starting FullTextIndex service go to SQL Server Tool->SQL Server Configuration Manage->Service->FullTextSearch Demon Launcher if it is stopped then start this service for performing search operation with a contains and FreeText clause and restart the SQL Server instance.

Conclusion

In this way we can use the FullTextIndex on our database.







Note:


EXEC sp_fulltext_database 'enable'
EXEC sp_fulltext_database 'disable'