Namespace Registration
Namespace Registration
Data
Source=myServerAddress;InitialCatalog=myDataBase;UserId=myUsername;Pa
ssword=myPassword;
namespace Registration
{
public partial class Form1 : Form
{
#region "declaration"
/*Declaring Connection variables
Here i had difined the connection variables so i can use
them anywhere*/
public string constring = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=" + Application.StartupPath + "/Records.mdb" +
";Persist Security Info=False";
Boolean states = false;
#endregion
public Form1()
{
InitializeComponent();
}
#region "filldatagrid"
//to fill data in Listview
public void fill(string str, string tstr)
{
listView1.Items.Clear();
listView1.Sorting = SortOrder.Ascending;
try
{
OleDbConnection con = new OleDbConnection(constring);
OleDbCommand com1 = new OleDbCommand(str, con);
con.Open();
OleDbDataReader datareader;
datareader = com1.ExecuteReader();
while (datareader.Read())
{
ListViewItem lvitem = new
ListViewItem(datareader[0].ToString());
for (int i = 1; i <= datareader.FieldCount - 1;
i++)
{
lvitem.SubItems.Add(datareader[i].ToString());
listView1.Items.Add(lvitem);
}
con.Close();
}
catch (Exception err) {
MessageBox.Show(err.ToString()); }
}
////////////////
private void filltext(string str, string tstr)
{
OleDbConnection con = new OleDbConnection(constring);
OleDbCommand com1 = new OleDbCommand(str, con);
con.Open();
OleDbDataReader datareader;
datareader = com1.ExecuteReader();
datareader.Read();
{
txtcode.Text =
datareader["Employee_Code"].ToString();
txtname.Text =
datareader["Employee_Name"].ToString();
txtaddress.Text =
datareader["Employee_Address"].ToString();
txtphone.Text =
datareader["Telephone_Number"].ToString();
txtsal.Text =
datareader["Monthly_Salary"].ToString();
txtjoin.Text = datareader["Joining_Date"].ToString();
}
datareader.Close();
con.Close();
}
//////////////////////
private void unable(bool a)
{
txtcode.Enabled = a;
txtname.Enabled = a;
txtaddress.Enabled = a;
txtphone.Enabled = a;
txtsal.Enabled = a;
txtjoin.Enabled = a;
#endregion
unable(false);
try
{
string str = "Select * from Employee_Details order by
Employee_Code";
string tstr = "Employee_Details";
// string cbtext = "Employee_Code";
fill(str, tstr);
filltext(str, tstr);
comboBox1.SelectedIndex = 0;
// listView1.SelectedItems =
listView1.Items.IndexOfKey("Emp001");
//MessageBox.Show(listView1.Items.Count.ToString());
//txtcode.Text =
(listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text);
}
catch (Exception err) {
MessageBox.Show(err.ToString()); }
}
private void textBox1_TextChanged(object sender,
EventArgs e)
{
//search the data which you enter in text box and select
the field from combo.
try
{
string cbtext = comboBox1.Text;
string str = "Select * from Employee_Details " +
"where " + comboBox1.Text + " like'%" + textBox1.Text + "%'";
string tstr = "Employee_Details";
fill(str, tstr);
//filltext(str, tstr, cbtext);
}
catch (Exception err) {
MessageBox.Show(err.ToString()); }
}
}
}