Monday, February 27, 2012

Upper case, Lower case, Proper Case or Title Case in C#


Convert a string to Uppercase

String Sub_Code = txtcode.Text.ToUpper();

Convert a string to Lowercase

String Sub_Code = txtcode.Text.ToLower();

Note : ToLower and ToUpper are methods of string class.

Convert a string to ProperCase or TitleCase
The String class does not include any method that converts a string to title case. To convert  a string to title case we use ToTitleCase method which resides in the TextInfo class, which is a member of the System.Globalization namespace. Unlike the ToUpper and ToLower methods of the String class, the ToTitleCase method is not a static method and requires an instance of the class.

When we use the TextInfo class, we must specify cultural information. CultureInfo class represents information about a specific culture including the names of the culture, the writing system, and the calendar used, as well as access to culture-specific objects that provide information for common operations, such as formatting dates and sorting strings.

Example :
CultureInfo cultureinfo = CultureInfo.InvariantCulture;
TextInfo textinfo = cultureinfo.TextInfo;

string Sub_Name =textinfo.ToTitleCase(txtname.Text);

 

Monday, February 20, 2012

Substring Function

For any function there arises three basic question--:
  1. What does it mean?
  2. Why is this?
  3. How it works?
What does it mean?
As we see SubString is a combination of two words "Sub" and "String".
String-: In Computer Science String  means "A set of consecutive characters".
Sub   -: Sub is basically a Latin prefix which has several meaning but the best suitable meaning for here is "part of".
So, Substring means "Part of a string".

Why is this?
So, from definition its clear that the work of substring is to extract a part of string.

How it works? 
Syntax : Substring(index,length)
            Here index denotes the postion from where you want to extract the string and length denotes up to how much character you need to extract.Both contains integer value.
Example :
        int ind = Convert.ToInt32(txtIndex.Text);
        int len = Convert.ToInt32(txtLength.Text);
        Literal1.Text = TextBox1.Text.Substring(ind,len); 


You can download Sample Code from Here 
 



Friday, February 17, 2012

An error has occurred during report processing. Exception has been thrown by the target of an invocation. Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

Yesterday I was using RDLC to create a matrix report and encountered by this problem
 "  An error has occurred during report processing.
        Exception has been thrown by the target of an invocation.
            Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
Basically this problem arises if a primary or foreign key defined in Table Adapter of DataSet which is used as Data Source for Report.
To resolve this just go to the relevent dataset and search for the primary key and just delete that.


Hope this will help you.

Monday, February 13, 2012

How To get Column Value From DataSet


This example shows how to get particular column value from a dataset. Even  We can get all values of that particular field using loop construct.

query = "SELECT [EnrollmentNo] FROM [vw_NewAttenInfo]";
SqlDataAdapter adp = new SqlDataAdapter(query,con);
DataSet ds = new DataSet();
adp.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count;i++)
{
…………
…………
string st = ds.Tables[0].Rows[i]["EnrollmentNo"].ToString();
……
……
}