Thursday, July 1, 2010

All Code Are Write in Program.cs

using System.Data;
using System.Data.OleDb;

public class Program
{
public string constr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DatabaseName.mdb";
}

This Method Is Use For The Insert , Update , Delete Also.
public void insertdata(string str)
{
try
{
OleDbConnection con = new OleDbConnection(constr);
con.Open();
OleDbCommand cmd = new OleDbCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();

}
catch (OleDbException ee)
{
MessageBox.Show(ee.ToString());
}
}

This Method Is Use For The Fetch Data From The Database
public object getdata(string str)
{
OleDbConnection con = new OleDbConnection(constr);
con.Open();
object a;
OleDbCommand cmd = new OleDbCommand(str, con);
a = cmd.ExecuteScalar();
con.Close();
return a;
}

This Method Is Use For The Read One Row At A Time
public object Dataread(string str)
{
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand cmd1 = new OleDbCommand(str, con);
con.Open();
OleDbDataReader dr;
return dr = cmd1.ExecuteReader();
}

This Method Is Use For The Fill The All ComboBox
public void fillcombobox(ComboBox ddl, string str)
{

OleDbConnection con = new OleDbConnection(constr);
OleDbDataAdapter dap = new OleDbDataAdapter(str, constr);
con.Open();

DataSet ds = new DataSet();
dap.Fill(ds);

for (int i = 0; i < text =" string.Empty;" text =" string.Empty;" text =" string.Empty;" selectedindex =" -1;" checked =" false;" checked =" false;"> 0)
{
//Call itself to get all other controls in other containers
ClearForm(ctrControl);
}
}
}

This Method Is Use For The Clear All Textbox,Reach TextBox,ComboBox,Etc...
public void ClearForm(System.Windows.Forms.Control parent)
{
foreach (System.Windows.Forms.Control ctrControl in parent.Controls)
{
//Loop through all controls
if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.TextBox)))
{
//Check to see if it's a textbox
((System.Windows.Forms.TextBox)ctrControl).Text = string.Empty;
//If it is then set the text to String.Empty (empty textbox)
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.RichTextBox)))
{
//If its a RichTextBox clear the text
((System.Windows.Forms.RichTextBox)ctrControl).Text = string.Empty;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.MaskedTextBox)))
{
//If its a MaskedTextBox clear the text
((System.Windows.Forms.MaskedTextBox)ctrControl).Text = string.Empty;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.ComboBox)))
{
//Next check if it's a dropdown list
((System.Windows.Forms.ComboBox)ctrControl).SelectedIndex = -1;
//If it is then set its SelectedIndex to 0
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.CheckBox)))
{
//Next uncheck all checkboxes
((System.Windows.Forms.CheckBox)ctrControl).Checked = false;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(System.Windows.Forms.RadioButton)))
{
//Unselect all RadioButtons
((System.Windows.Forms.RadioButton)ctrControl).Checked = false;
}
if (ctrControl.Controls.Count > 0)
{
//Call itself to get all other controls in other containers
ClearForm(ctrControl);
}
}
}

Friday, April 2, 2010

How to Formate Date String in C# : Windows Application

Write the code given below and convert datetime to Desirable Format textBox1.Text = String.Format("{0:dd/MM/yyyy}",DateTime.Now);For More Format string Click the link Given Belowhttp://www.csharp-examples.net/string-format-datetime/