Pages

Sunday, December 20, 2009

Frequently asked ASP.Net Interview Questions List ASP.Net Interview Questions

Frequently asked ASP.Net Interview Questions List ASP.Net Interview Questions


1. Explain the differences between Server-side and Client-side code?
2. What type of code (server or client) is found in a Code-Behind
class?
3. Should validation (did the user enter a real date) occur
server-side or client-side? Why?
4. What does the "EnableViewState" property do? Why would I want it on or off?
5. What is the difference between Server.Transfer and

Friday, December 18, 2009

Earn money with PayPal through the referral bonus program Get PayPal Account PayPal Referral Bonus

Earn money with PayPal through the referral bonus program Get PayPal Account PayPal Referral Bonus
https://www.paypal.com/
First login to your PayPal account, then click on "Referrals" at the footer of the site, as you can see in the following image:

Within the page will find the referral link and the official PayPal banner and HTML code.

Paste this HTML code to your site or blog ..

Thursday, December 17, 2009

Interview Questions: C# ASP.NET DataGrid Questions Interview What is datagrid Hide the columns Customize the Column Formatting to the data inside the cells Reference MSDN


ASP.NET DataGrid Questions 
Interview Questions: C#

1.      What is datagrid? The DataGrid Web server control is a powerful tool for displaying information from a data source. It is easy to use; you can display editable data in a professional-looking grid by setting only a few properties. At the same time, the grid has a sophisticated object model that provides you with great flexibility in how you display the data.

Monday, November 23, 2009

Monday, November 16, 2009

IsNumeric function in C# equivalent to VB6 IsNumeric() By Praveen P R

// C# .NET
//Check Value if numeric
public static bool IsNumeric(object Expression)
{
bool isNum;
double retNum;
isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
return isNum;
}
http://prpraveen.blogspot.com/

Thursday, November 12, 2009

Focus to next Control in winform on Enter Key Press C# By Praveen PR

Step 1.
//Add the funtion in any common class (static class) so the you can access if from any form you added

//Send Focus to next Control in Form
public static void sendTab(Keys sendKey, object sender)
{
if (sendKey == Keys.Enter)
{
SendKeys.Send("{TAB}");
}
else if (sendKey == Keys.Right)
{
//if (sender.GetType().Name != "DateTimePicker")
//{
// SendKeys.Send("{TAB}");
//}

Saturday, October 24, 2009

System.Data.SqlClient.SqlException: Directory lookup for the file...failed with the operating system error 5(Access is denied.)

//E.g SqlExpress
1.Click the Windows Start button, and then click Run. The Run dialog box appears.
2.Type Services.msc into the Open field, and then click OK. The Services
panel appears:
3.Right-click the SQL Server (SqlEx[ress) service, and then click Properties from the shortcut menu. The SQL Server (SqlExpress) Properties (Local Computer) dialog box appears:
4.On the Log On tab, select Local System account for the Log on as option.
5.Press Apply and then press OK on the dialog box that appears.
6.Click on the General tab and then press Stop the stop the service, and Start to restart the SqlExpress service.
7.Press OK and close the services Console.
8.Launch SqlExpress and attempt to now restore the database.
http://www.prpraveen.blogspot.com

Monday, October 19, 2009

Problem while Saving modified .bmp file A generic error occurred in GDI+. C# .net By Praveen P.R

//Problem while Saving modified .bmp file
//A generic error occurred in GDI+.
//Do the following

//some function...... inside it.....
 try
  {
  System.GC.Collect();//imp
  System.GC.WaitForPendingFinalizers();//imp
  if (System.IO.File.Exists(Application.StartupPath + @"\Alpha100.bmp"))
  {
  System.IO.File.Delete(Application.StartupPath + @"\Alpha100.bmp");
  }
  myBitmap.Save(Application.StartupPath + @"\Alpha100.bmp");
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.ToString());
  }

Steps to Create a Crystal Report based on an XML schema (XSD) file.

1.Create Dataset with.(e.g Select * from anytable)
Note:-Basic knowledge of C# required
2.e.g Dataset ds;
3.Then write the following code e.g ds.WriteXmlSchema("RptDailyAll.xsd");
4.Above code will genrate "RptDailyAll.xsd" file in the current directory
5.Now open a new crystall report and follow the steps as seen in images


Tuesday, October 13, 2009

Steps VSS Visual Source Safe .net By Praveen P.R

Step to Manage VSS

1.Create folder for VSS this will act as Server Database.
2.Make  this folder shared .So to access for client System.
2.Now take-->Microsoft Visual SourceSafe Administration(Programs->Microsoft Visual SourceSafe-->)
3 Create new database
   Menu File-->New DataBase...

Monday, October 12, 2009

Install .bak file at first run / installation C# By Praveen P.R

//This is to show how to restore your .bak file (SQL Express) when your first  run the application
1. Add this code in your app.config file
add key="ConnectionString" value="Data Source=.\sqlexpress;Initial Catalog=Transactions;Integrated Security=True" 
  add key="ConnectionStringM" value="Data Source=.\sqlexpress;Initial Catalog=master;Integrated Security=True"  
using connectionstring added above
using System.Configuration;this.connectionString = ConfigurationSettings.AppSettings["ConnectionString"]; 
2. Above code is to connect to sql express default database

3.Now when your application runs for the first time check the name of the database if it exists in sql express
with  the above connection string.
4.for eg.
  CheckDBExist("Transactions");//database name
5.

 private bool CheckDBExist(string dbName)
  {
  BLLTransaction bllTransaction = new BLLTransaction(classGlobal.connectionStringM);
  DataSet dsChkDBExist;
  dsChkDBExist = bllTransaction.Select("select * from sys.databases where name = '" + dbName + "'");
  if (dsChkDBExist.Tables[0].Rows.Count == 0)
  {
  DialogResult result = MessageBox.Show("Database not found.\nDo you want to Restore Database?", "Restore Database", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  if (result == DialogResult.Yes)
  {
  try
  {
  Server mServer = new Server(@".\sqlexpress");
  //mServer.KillAllProcesses("Transactions");
  //mServer.DetachDatabase("Transactions", true);

  //Application.StartupPath.Replace only needed at project devlopment
  File.Move(Application.StartupPath.Replace("bin\\Debug", "") + @"TranDB\Transactions.mdf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions.mdf");
  File.Move(Application.StartupPath.Replace("bin\\Debug", "") + @"TranDB\Transactions_log.ldf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions_log.ldf");

  //File.Move(Application.StartupPath + @"TranDB\Transactions.mdf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions.mdf");
  //File.Move(Application.StartupPath + @"TranDB\Transactions_log.ldf", @"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions_log.ldf");

  StringCollection files = new StringCollection();
 
  files.Add(@"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions.mdf");
  files.Add(@"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\data\Transactions_log.ldf");

  mServer.AttachDatabase("Transactions", files, AttachOptions.None);
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.ToString());
  }
  }
  }
  return true;
  }

6.The above code have my bll class which i use for connection above code to give some idea ;)
 7.getSqlExpressPath() //to get sqlexpress path

private string getSqlExpressPath()
{
string path = "";
using (RegistryKey sqlServerKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server"))
{
foreach (string subKeyName in sqlServerKey.GetSubKeyNames())
{
if (subKeyName.StartsWith("MSSQL."))
{
using (RegistryKey instanceKey = sqlServerKey.OpenSubKey(subKeyName))
{
string instanceName = instanceKey.GetValue("").ToString();

if (instanceName == "SQLEXPRESS")//say
{
path = instanceKey.OpenSubKey(@"Setup").GetValue("SQLBinRoot").ToString();
path = Path.Combine(path, "sqlserver.exe");

}
}
}
}
}
return path;
}

http://www.prpraveen.blogspot.com


Thursday, October 8, 2009

Backup DataBase as .bak sql express 2005 C# .Net By Praveen P.R

using Microsoft.SqlServer.Management;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Windows.Forms;

  public void BackupDatabase(String databaseName, String userName, String password, String serverName, String destinationPath)
  {
  try
  {
  Backup sqlBackup = new Backup();

  sqlBackup.Action = BackupActionType.Database;
  sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
  sqlBackup.BackupSetName = "Archive";

  sqlBackup.Database = databaseName;

  BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
  //Backup bu = new Backup();
  //bu.Database = databaseName;

  //bu.Devices.Add(deviceItem);

  //bu.Initialize = true;
  //bu.PercentCompleteNotification = 10;
  //// add percent complete and complete event handlers

  //bu.PercentComplete += new PercentCompleteEventHandler(Backup_PercentComplete);

  //bu.Complete += new ServerMessageEventHandler(Backup_Complete);

  //ServerConnection connection = new ServerConnection(serverName,userName,password);

  ServerConnection connection = new ServerConnection(serverName);
  Server sqlServer = new Server(connection);

  Database db = sqlServer.Databases[databaseName];

  sqlBackup.Initialize = true;
  sqlBackup.Checksum = true;
  sqlBackup.ContinueAfterError = true;

  sqlBackup.Devices.Add(deviceItem);
  sqlBackup.Incremental = false;

  sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
  sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;

  sqlBackup.FormatMedia = false;

  sqlBackup.SqlBackup(sqlServer);
  MessageBox.Show("Database Backup success....\nBackup file in " + destinationPath + ".", "Backup success", MessageBoxButtons.OK, MessageBoxIcon.None);
  }
  catch(Exception ex)
  {
  MessageBox.Show("Database Backup failed....", "Backup failed\n"+ex.InnerException.ToString () +"", MessageBoxButtons.OK, MessageBoxIcon.Error);
  }
  }

http://www.prpraveen.blogspot.com

Wednesday, October 7, 2009

Restore .bak file sql express 2005 C# .Net By Praveen P.R

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Windows.Forms;
public void RestoreDatabase(string databaseName,string backupFileName,String serverName)
  {
  try
  {
  ServerConnection connection = new ServerConnection(serverName);//".\sqlexpress"
  Server server = new Server(connection);

  Restore restore = new Restore();
  restore.Database = databaseName;//

 //backupFileName e.g database.bak
  restore.Devices.AddDevice(backupFileName, DeviceType.File);
  restore.ReplaceDatabase = true;
  restore.ReplaceDatabase = true;
  restore.PercentCompleteNotification = 10;
  server.KillAllProcesses(databaseName);
  restore.Wait();
  restore.SqlRestore(server);
  MessageBox.Show("Database Restore success....", "Restore success", MessageBoxButtons.OK, MessageBoxIcon.None);
  }
  catch (Exception ex)
  {
  System.Windows.Forms.MessageBox.Show(ex.InnerException.ToString());
  }
  }

http://www.prpraveen.blogspot.com

Monday, September 21, 2009

Save a datetime into SQL Server 2005 in dd/MM/yyyy format By Praveen P.R

y//C#
//Save datetime in dd/MM/yyy formate into DataBase

//While Insert statement
e.g
Insert into ....purchaseDate="'+ DateTime.ParseExact(dateTimeField.Value.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture.DateTimeFormat)+"' .....;

//While Select statement
 e.g
Select
convert(datetime,purchaseDate,103) =convert(datetime,'" + DateTime.ParseExact(dateTimeField.Value.ToString("dd/MM/yyyy"), "dd/MM/yyyy", CultureInfo.InvariantCulture.DateTimeFormat) + "',103) ,.........from tablename

http://www.prpraveen.blogspot.com

Datetime Null insertion to DataBase By Praveen P.R

//C#
//Datetime Null insertion to DB

using System.Data.SqlTypes;

//Any Datetime variable
//e.g dtToday
dtToday= SqlDateTime.Null;

http://www.prpraveen.blogspot.com

Sunday, September 20, 2009

DataGridView ComboBox Single click DropDown By Praveen P.R

// C#//It is also possible to drop down the comboboxlist using the DataGridViewComboBoxEditingControl when catching a mouse event:


 private void dgvCompanyList_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  {
  if(dgvCompanyList[e.ColumnIndex, e.RowIndex].EditType.ToString() == "System.Windows.Forms.DataGridViewComboBoxEditingControl")
  {
  DataGridViewColumn column = dgvCompanyList.Columns[e.ColumnIndex];
  if (column is DataGridViewComboBoxColumn)
  {
  DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgvCompanyList[e.ColumnIndex, e.RowIndex];
  dgvCompanyList.CurrentCell = cell;
  dgvCompanyList.BeginEdit(true);
  DataGridViewComboBoxEditingControl editingControl = (DataGridViewComboBoxEditingControl)dgvCompanyList.EditingControl;
  editingControl.DroppedDown = true;
  }
  }
  }
http://www.prpraveen.blogspot.com

How to trigger a button click event By Praveen P.R

//C#

 button1.PerformClick();
 button1_Click(null, null);

prpraveen.blogspot.com

Monday, September 14, 2009

GlassButton / Custom button C# By Praveen P.R


http://www.prpraveen.blogspot.com
Codeproject

 * GlassButton - How to create an animating glass button using only GDI+ (and not using WPF). *
 * *
 * Original developed by Łukasz Świątkowski - lukasz.swiatkowski@gmail.com *
 * Form-/Perfomance-/Behavior-Improvements by Fink Christoph - fink.christoph@gmail.com *
 * *
 * Perfomance-Timer stoped for slow systems
 * Feel free to use this control in your application or to improve it in any way! *
 ***********************************************************************************************/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using PushButtonState = System.Windows.Forms.VisualStyles.PushButtonState;

namespace EnhancedGlassButton
{
  ///
  /// Represents a glass button control.
  ///

  [ToolboxBitmap(typeof(System.Windows.Forms.Button)), ToolboxItem(true), ToolboxItemFilter("System.Windows.Forms"), Description("Raises an event when the user clicks it.")]
  public partial class GlassButton : Button
  {
  # region " Global Vareables "

  # region " Vareables for Drawing "

Sunday, September 6, 2009

Set Focus to a control on Form Load C# by Praveen P.R

// On form Load as  required
this.ActiveControl = controlName;

Clear all controls on a Form / Panel / GroupBox etc c# by Praveen P.R

 //Clear All values in the Form / Panel / GroupBox  etc
  public static void clearControls(Control crl)
  {
  foreach (Control c in crl.Controls)
  {
  if (c.GetType().Name == "GroupBox" || c.GetType().Name == "CustomGroupBox")
  {
  clearControls(c);
  }
  else if (c.GetType().Name == "TextBox")
  {
  ((TextBox)c).Text = "";
  }
  else if (c.GetType().Name == "CustomTextBox")
  {
  ((CustomControls.CustomTextBox)c).Text = "";
  }
  else if (c.GetType().Name == "ComboBox")
  {
  if (((ComboBox)c).Items.Count > 0)
  {
  ((ComboBox)c).SelectedIndex = 0;
  }
  }
  }
  }
//To call the above funtion

clearControls(this);
or
clearControls(panel); // pass panel Object

or
clearControls(Groupbax); // pass groupbax Object

Monday, August 31, 2009

Runtime Change control Position / location C# by Praveen P.R

// Code in C#

Using Button btnSave
//Change position / location  in the form
btnSave.Location = new System.Drawing.Point(300,272);//300= X,272= Y

C# Add | Fill ComboBox with Enum values C# By Praveen P.R

// Code in C# Add | Fill ComboBox with Enum values
//Declair Enum

public enum UserLevel { Admin = 0, Client = 1, Other = 2, Agent = 3, Supplier = 4, Accounts = 5, CheckPost = 6, Manager = 7 };

//Filling combobox with Enun Values

cmbUserLevel.DataSource = Enum.GetValues(typeof(classEnum.UserLevel));

//Set initial Value

cmbUserType.SelectedItem = classEnum.UserLevel.Other;

//Getting Selected Values

 classEnum.UserTypeAtGoodsRecpt usr = (classEnum.UserTypeAtGoodsRecpt)Enum.Parse(typeof(classEnum.UserTypeAtGoodsRecpt), cmbUserType.SelectedItem.ToString());

// To get the value
int userVal=(int)usr;

Friday, August 28, 2009

Change First Letter to Capital letter C# by Praveen P.R

// Code in C#
//Change First Letter to Capital letter

public static string titleCase(string text)
  {
  string returnTiltle;
  CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; //Convert to title case
  TextInfo textInfo = cultureInfo.TextInfo; //Convert to title case
  return returnTiltle = textInfo.ToTitleCase(text.Trim());
  }

Get System Drives C# by Praveen P.R

// Code in C#

//Get System Drives
public static void getSystemDrives(ComboBox cmbBox)
  {
  DriveInfo[] allDrives = DriveInfo.GetDrives();

  foreach (DriveInfo d in allDrives)
  {
  if (d.IsReady)
  {
  cmbBox.Items.Add((object)d.Name);
  }
  }
  if (cmbBox.Items.Count > 0)
  {
  cmbBox.SelectedIndex = 0;
  }
  }

Close a Form Slowly C# by Praveen P.R

// Code in C#
//Close a form Slowly C#
  public static void closeWindowSlowly(Form currentForm)
  {
  lock (currentForm)
  {
  for (double x = 1.0d; x > 0d; x = x - 0.1d)
  {
  System.Threading.Thread.Sleep(50);
  currentForm.Opacity = x;
  currentForm.Refresh();
  }
  }
  }

Thursday, August 27, 2009

Gradient Effect to Controls C# by Praveen P.R

// Code in C#

Give gradient effect to control at Paint Event

  private void Form1_Paint(object sender, PaintEventArgs e)
  {
  System.Drawing.Drawing2D.LinearGradientBrush gradBrush;
  Point start = new Point(-100,-100);
  Point end = new Point(Form1.Width-1000, Form1.Height+1300);
  gradBrush = new
  System.Drawing.Drawing2D.LinearGradientBrush(start, end, Color.Black, Color.Honeydew );
  Graphics g = Form1.CreateGraphics();
  g.FillRectangle(gradBrush, new Rectangle(0,0,Form1.Width, Form1.Height));
  }

Saturday, July 11, 2009

About me

Hello it's me P.R.Praveen from Kerala.

Currently working as Software Engineer.