2009-11-27

How to get a database backup from SQL server

Right click on the database and select Tasks –> Backup….

Untitled

  Then select the database from the list of   available databases and select the destination folder by clicking on the Add button. Following image demonstrates that…

 

 

 

 

 

 

 

 

Untitled1

2009-11-25

How to get a appSettings value in a web.config file

Lets assume the following line has put between the <appSettings></appSettings> node.

<add key="StartingDate" value="09-05-2008" />

Now say, we want to get the value of the “StartingDate” in our C#.net code. All you want to do is, include the following line where you want to get the value.

ConfigurationManager.AppSettings["StartingDate"].ToString()

From the above line of code, you can get the “09-05-2008” value in your .net code.

Note: First of all you have to import the System.Configuration using the following code.

using System.Configuration;

2009-11-20

How to make the asp:HyperLink underlined and bold after clicked.

In C#.net code, call the asp:HyperLink controller by the id and apply the style as shown below.

name_of_the_controller.Style.Add("text-decoration", "underline");
name_of_the_controller.Style.Add("font-weight", "bold");

2009-11-19

How to set the alignment and font of the data in a column in asp:GridView

In the design view, click on the arrow shown in the top left corner of the asp:GridView component to get the GridView Tasks and then select ‘Edit columns…’. Then click on the minus sign of the ItemStyle to expand the properties. Then do the changes as shown below.

screen

2009-11-09

Method to erase the text from set of labels/textboxes at one glance in an iPhone application.

-(void)resetLabels{

Label1.text = @””;

Labe2.text = @””;

………………………….

}

If you want to erase the text from set of textboxes, do the same thing replaces the labels with text boxes. ;) Then call the method where appropriate. :)

How to move rows in a table in an iPhone application

Override the following delegate method to allow row moving.

-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{

return YES;

}

-(void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath{

NSUInteger rowFrom = [fromIndexPath row];

NSUInteger rowTo = [toIndexPath row];

id idObject = [[array objectAtIndex: rowFrom] retain];

[array removeObjectAtIndex: rowFrom];

[array insertObject: idObject atIndex: rowTo];

[idObject release];

}

Override the above delegate method to do the actual row moving.

How to delete a row from a table in an iPhone application

Override the following delegate method as follows.

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

NSUInteger rowNumber = [indexPath row];

[self.array removeObjectAtIndex: rowNumber];

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

How to add an additional button to the navigation bar in an iPhone application

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"Additional" style:UIBarButtonItemStyleBordered target:self action:@selector(additionalAction:)];

self.navigationItem.rightBarButtonItem = barButton;

[barButton release];

How to initiate an NSDictionary type of object with the contents of a plist

NSString *pathForplist = [[NSBundle mainBundle] pathForResource:@"Objects" ofType:@"plist"];

NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile: pathForplist];

In my example, the plist file name is ‘Objects’.

How to play sound in an iPhone application

In the header file you must import the ‘AudioToolbox.h’ file in order to application to support for sounds. Add the following line of code in the top of the header file to import it.

#import <AudioToolbox/AudioToolbox.h>

Add the following line of codes inside the @interface in the header file.

SystemSoundID systemSoundID;

NSString *soundFilePath;

Then generate the getter and setter methods by adding the following line of code to the bottom of header file

@property (nonatomic, retain) NSString * soundFilePath;

and including the following line of code in the top of the .m file.

@synthesize soundFilePath;

Then import the sound file into your resources folder. In my example I imported an mp4 type file called ‘ruchira.mp4’.

Find the path to the sound file by adding the following code.

soundFilePath = [[NSBundle mainBundle] pathForResource:@"ruchira" ofType:@"mp4"];

Then create the system sound id for our sound file by adding the following code.

AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundFilePath], & systemSoundID);

Then add the following line of code where you actually want to play that sound. For example, if you want to play the sound when a button taps, and then includes the following code in the button action method.

AudioServicesPlaySystemSound(systemSoundID);

How to add an action sheet to an iPhone application

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose either one option" delegate:self cancelButtonTitle:@"I don’t need that" destructiveButtonTitle:@"I want to go there" otherButtonTitles:nil];

[actionSheet showInView:self.view];

[actionSheet release];

Action sheets come to handy when the application wants to prompt the user with options and user should not continue without selecting one option.

How to check the iPhone/iPod is camera supported or not from the application

All iPhone versions up to now are implicitly camera supported. But when we are writing iPhone apps, those can be run in iPhones as well as iPods. iPod don’t have a camera, so we have to check in the application, whether the application is deployed in an iPhone or in an iPod. Rather than doing that, we can check whether the device is camera supported or not by adding the following line of code.

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]

We can also check whether the device support for a Photo Library or not by following line of code.

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]

How to allow landscape orientation in an iPhone application

Override the shouldAutorotateToInterfaceOrientation method in the particular view class file, as follows

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);

}

Now the view is supported for landscape orientation.

2009-11-06

How to change the selected page number color in asp:GridView

Add the following lines in to css file.

.pager span 
{
    color:#000000;
    font-family: "Trebuchet MS";
    font-size: 14px;
    line-height: 20px;
}

Note: You can change the styles accordingly.

Add the following line in between <asp:GridView></asp:GridView> tags.

<PagerStyle BackColor="#EBEBEB" BorderColor="#EBEBEB" BorderStyle="Solid"
                        HorizontalAlign="Right" CssClass="pager" ForeColor="#0049B2" />

Fore color is the default color for page numbers other than the selected page.

2009-11-05

How to prevent the web browser from caching a web page

Include the lines shown below between the <head> </head> tags in the HTML page.

Ex:-

<head>

<meta http-equiv="Expires" CONTENT="0">

<meta http-equiv="Cache-Control" CONTENT="no-cache">

<meta http-equiv="Pragma" CONTENT="no-cache">

</head>

How to compare two databases in separate SQL servers and generate the SQL scripts

image

I have used a software called :”AdeptSQL Diff” to compare two databases from different SQL servers. It shows the tables, stored procedures, functions and other items one by one very clearly. From this software it is easy to compare the two databases and get to know what are the items available in one database and what are the items not available. We can also generate the scripts to make the two databases same by tables/stored procedures/functions/users. It is a very good software to even do modifications and run the scripts from there. From that software we can easily make the two databases same.