1,105,578 Community Members

Help with project

Member Avatar
deepak690
Newbie Poster
5 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Friends i want to submit project in my college on employee management system....
front end should be c# and back end sql server 2008...
i got one project on net but its backend is microsoft access I want to change this to sql server 2008....
what changes i have to do in project....pls help...its really urgent.....

here is project
http://dl.dropbox.com/u/29676246/A1_Employe2077567302007.rar

http://dl.dropbox.com/u/29676246/A1_Employe2077567302007.rar

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

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


#region "insert save delete record"
        private void saverecord()
        {
            OleDbConnection savecon = new OleDbConnection(constring);
            OleDbCommand savecom = new OleDbCommand("insert into Employee_Details values (?,?,?,?,?,?)", savecon);
            OleDbParameter param;
            param = savecom.Parameters.Add("@empcode", OleDbType.VarChar, 10);
            param.Value = txtcode.Text;
            param = savecom.Parameters.Add("@empname", OleDbType.VarChar, 25);
            param.Value = txtname.Text;
            param = savecom.Parameters.Add("@empadd", OleDbType.VarChar, 50);
            param.Value = txtaddress.Text;
            param = savecom.Parameters.Add("@empphone", OleDbType.VarChar, 20);
            param.Value = txtphone.Text;
            param = savecom.Parameters.Add("@empsal", OleDbType.VarChar, 7);
            param.Value = txtsal.Text;
            param = savecom.Parameters.Add("@empjoin", OleDbType.Date);
            param.Value = DateTime.Now.ToShortDateString();
            savecon.Open();
            int rows = savecom.ExecuteNonQuery();
            MessageBox.Show(rows.ToString() + "rows affected");
            btnref.PerformClick();
            savecon.Close();
        }
        private void updaterecord()
        {
            OleDbConnection upcon = new OleDbConnection(constring);
            OleDbCommand upcom = new OleDbCommand("Update Employee_Details set Employee_Name=?, Employee_Address=?, Telephone_Number=?, Monthly_Salary=?, Joining_Date=?" + "where Employee_Code=?",upcon);
            OleDbParameter param;
            param = upcom.Parameters.Add("@empname", OleDbType.VarChar, 25);
            param.Value = txtname.Text;
            param = upcom.Parameters.Add("@empadd", OleDbType.VarChar, 50);
            param.Value = txtaddress.Text;
            param = upcom.Parameters.Add("@empphone", OleDbType.VarChar, 20);
            param.Value = txtphone.Text;
            param = upcom.Parameters.Add("@empsal", OleDbType.VarChar, 7);
            param.Value = txtsal.Text;
            param = upcom.Parameters.Add("@empjoin", OleDbType.Date);
            param.Value = DateTime.Now.ToShortDateString();
            param = upcom.Parameters.Add("@empcode", OleDbType.VarChar, 10);
            param.Value = txtcode.Text;
            upcon.Open();
            int rowss = upcom.ExecuteNonQuery();
            MessageBox.Show(rowss.ToString() + "rows effected");
            btnref.PerformClick();
            upcon.Close();
        }
        private void deleterecord() 
        {
            OleDbConnection delcon = new OleDbConnection(constring);
            OleDbCommand delcom = new OleDbCommand("Delete from Employee_Details where Employee_Code='" + txtcode.Text + "'",delcon);
            delcon.Open();
            int rows = delcom.ExecuteNonQuery();
            MessageBox.Show(rows.ToString() + " Rows Deleted");
            btnref.PerformClick();
            delcon.Close();
        }
        #endregion
        


       



        private void toolStripButton14_Click(object sender, EventArgs e)
        {//close the form
            this.Close();
        }




        private void toolStripButton6_Click(object sender, EventArgs e)
        {//Reload the data
            unable(false);
            try
            {
                string str = "Select * from Employee_Details order by Employee_Code";
                string tstr = "Employee_Details";
                fill(str, tstr);
                filltext(str, tstr);
                comboBox1.SelectedIndex = 0;
            }
            catch (Exception er) { MessageBox.Show(er.ToString()); }
        }




    
       
              
        private void Form1_Load(object sender, EventArgs e)
        {
            //it will fill the listview with data on load event
            //Calling the connect function which we had difined earlier
            
            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()); }
        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            label10.Visible = true;
            label10.Text = "Adding Records";
            unable(true);
            txtjoin.Enabled = false;
            txtjoin.Text = DateTime.Now.ToShortDateString();
            txtcode.Text = "";
            txtname.Text = "";
            txtaddress.Text = "";
            txtphone.Text = "";
            txtsal.Text = "";
            
        }

       

        private void btnEdit_Click(object sender, EventArgs e)
        {
            label10.Visible = true;
            label10.Text = "Editing Record : First Click on Record list which you want to Edit";
            states = true;
            unable(true);
            txtjoin.Enabled = false;
            txtjoin.Text = DateTime.Now.ToShortDateString();

        }

        private void btnref_Click(object sender, EventArgs e)
        {
            unable(false);
            try
            {
                string str = "Select * from Employee_Details order by Employee_Code";
                string tstr = "Employee_Details";
                fill(str, tstr);
                filltext(str, tstr);
                comboBox1.SelectedIndex = 0;
            }
            catch (Exception er) { MessageBox.Show(er.ToString()); }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            //close the form
            this.Close();
        }

        private void btndelete_Click(object sender, EventArgs e)
        {
            deleterecord();
        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            if (states == false)
            {
                saverecord();
            }
            else { updaterecord(); }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtcode.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text);
            txtname.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[1].Text);
            txtaddress.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[2].Text);
            txtphone.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[3].Text);
            txtsal.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[4].Text);
            txtjoin.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[5].Text);
        }
    }
}
Member Avatar
mani-hellboy
Junior Poster in Training
69 posts since Feb 2012
Reputation Points: -10 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 0 [?]
 
0
 

Hey Dude.,

First you want to create the Database in SQL SERVER which have same schema of your current Access database
Second then replace the name space where you used System.data.OLEDB name space into Syatem.Data.SQLclient
third thing change the oledbconnection to SQLconnection , Oledb command to sqlcommand,and oledb related object into sql server related object

Note: use second and third in Front end,first only in SQL server

Member Avatar
deepak690
Newbie Poster
5 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

ok i will try....

Member Avatar
deepak690
Newbie Poster
5 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@mani-hellboy WHT u written in note i didnt get that...

Member Avatar
deepak690
Newbie Poster
5 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Friends i did this changes with sql database but it still gives error

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//using System.Data.OleDb;
using System.Data.SqlClient;

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;

        constrin.ConnectionString ="Data Source=DVIRUS\\SQLSERVER;Initial Catalog=employee_details;Integrated Security=True";

       public SqlConnection constrin = new SqlConnection();

#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
            {
                SqlConnection con = new SqlConnection(constrin);
                SqlCommand com1 = new SqlCommand(str, con);
                con.Open();
                SqlDataReader datareader;
                datareader = com1.ExecuteReader();



                //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)
        {
            SqlConnection con = new SqlConnection(constrin);
            SqlConnection com1 = new SqlCommand(str, con);
            con.Open();
            SqlDataReader datareader();
            datareader.Read();

           // 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


#region "insert save delete record"
        private void saverecord()
        {
            SqlConnection savecon = new SqlConnection(constrin);
            SqlCommand savecom = new SqlCommand("insert into Employee_Details values (?,?,?,?,?,?)", savecon);
            SqlParameter param;


            //OleDbConnection savecon = new OleDbConnection(constring);
            //OleDbCommand savecom = new OleDbCommand("insert into Employee_Details values (?,?,?,?,?,?)", savecon);
            //OleDbParameter param;


            param = savecom.Parameters.Add("@empcode", SqlDbType.VarChar, 10);
            param.Value = txtcode.Text;
            param = savecom.Parameters.Add("@empname", SqlDbType.VarChar, 25);
            param.Value = txtname.Text;
            param = savecom.Parameters.Add("@empadd", SqlDbType.VarChar, 50);
            param.Value = txtaddress.Text;
            param = savecom.Parameters.Add("@empphone", SqlDbType.VarChar, 20);
            param.Value = txtphone.Text;
            param = savecom.Parameters.Add("@empsal", SqlDbType.VarChar, 7);
            param.Value = txtsal.Text;
            param = savecom.Parameters.Add("@empjoin", SqlDbType.Date);
            param.Value = DateTime.Now.ToShortDateString();
            savecon.Open();
            int rows = savecom.ExecuteNonQuery();
            MessageBox.Show(rows.ToString() + "rows affected");
            btnref.PerformClick();
            savecon.Close();
        }
        private void updaterecord()
        {
            SqlConnection upcon = new SqlConnection(constrin);
            SqlCommand upcom = new SqlCommand("update Employee_Details set Employee_Name=?, Employee_Address=?, Telephone_Number=?, Monthly_Salary=?, Joining_Date=?" + "where Employee_Code=?",upcon);
            SqlParameter param;
            //OleDbConnection upcon = new OleDbConnection(constring);
            //OleDbCommand upcom = new OleDbCommand("Update Employee_Details set Employee_Name=?, Employee_Address=?, Telephone_Number=?, Monthly_Salary=?, Joining_Date=?" + "where Employee_Code=?",upcon);
            //OleDbParameter param;
            param = upcom.Parameters.Add("@empname", SqlDbType.VarChar, 25);
            param.Value = txtname.Text;
            param = upcom.Parameters.Add("@empadd", SqlDbType.VarChar, 50);
            param.Value = txtaddress.Text;
            param = upcom.Parameters.Add("@empphone", SqlDbType.VarChar, 20);
            param.Value = txtphone.Text;
            param = upcom.Parameters.Add("@empsal", SqlDbType.VarChar, 7);
            param.Value = txtsal.Text;
            param = upcom.Parameters.Add("@empjoin", SqlDbType.Date);
            param.Value = DateTime.Now.ToShortDateString();
            param = upcom.Parameters.Add("@empcode", SqlDbType.VarChar, 10);
            param.Value = txtcode.Text;
            upcon.Open();
            int rowss = upcom.ExecuteNonQuery();
            MessageBox.Show(rowss.ToString() + "rows effected");
            btnref.PerformClick();
            upcon.Close();
        }
        private void deleterecord() 
        {
            SqlConnection delcon = new SqlConnection(constrin);

            SqlCommand delcom = new SqlCommand("Delete from Employee_Details where Employee_Code='" + txtcode.Text + "'", delcon);

            //OleDbConnection delcon = new OleDbConnection(constring);
            //OleDbCommand delcom = new OleDbCommand("Delete from Employee_Details where Employee_Code='" + txtcode.Text + "'",delcon);
            //delcon.Open();
            int rows = delcom.ExecuteNonQuery();
            MessageBox.Show(rows.ToString() + " Rows Deleted");
            btnref.PerformClick();
            delcon.Close();
        }
        #endregion







        private void toolStripButton14_Click(object sender, EventArgs e)
        {//close the form
            this.Close();
        }




        private void toolStripButton6_Click(object sender, EventArgs e)
        {//Reload the data
            unable(false);
            try
            {
                string str = "Select * from Employee_Details order by Employee_Code";
                string tstr = "Employee_Details";
                fill(str, tstr);
                filltext(str, tstr);
                comboBox1.SelectedIndex = 0;
            }
            catch (Exception er) { MessageBox.Show(er.ToString()); }
        }







        private void Form1_Load(object sender, EventArgs e)
        {
            //it will fill the listview with data on load event
            //Calling the connect function which we had difined earlier

            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()); }
        }

        private void btnadd_Click(object sender, EventArgs e)
        {
            label10.Visible = true;
            label10.Text = "Adding Records";
            unable(true);
            txtjoin.Enabled = false;
            txtjoin.Text = DateTime.Now.ToShortDateString();
            txtcode.Text = "";
            txtname.Text = "";
            txtaddress.Text = "";
            txtphone.Text = "";
            txtsal.Text = "";

        }



        private void btnEdit_Click(object sender, EventArgs e)
        {
            label10.Visible = true;
            label10.Text = "Editing Record : First Click on Record list which you want to Edit";
            states = true;
            unable(true);
            txtjoin.Enabled = false;
            txtjoin.Text = DateTime.Now.ToShortDateString();

        }

        private void btnref_Click(object sender, EventArgs e)
        {
            unable(false);
            try
            {
                string str = "Select * from Employee_Details order by Employee_Code";
                string tstr = "Employee_Details";
                fill(str, tstr);
                filltext(str, tstr);
                comboBox1.SelectedIndex = 0;
            }
            catch (Exception er) { MessageBox.Show(er.ToString()); }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            //close the form
            this.Close();
        }

        private void btndelete_Click(object sender, EventArgs e)
        {
            deleterecord();
        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            if (states == false)
            {
                saverecord();
            }
            else { updaterecord(); }
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtcode.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text);
            txtname.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[1].Text);
            txtaddress.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[2].Text);
            txtphone.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[3].Text);
            txtsal.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[4].Text);
            txtjoin.Text = (listView1.Items[listView1.FocusedItem.Index].SubItems[5].Text);
        }
    }
}
Member Avatar
kamilacbe
Junior Poster
104 posts since Jun 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 11 [?]
Skill Endorsements: 0 [?]
 
0
 

hi..

what error does it produce...

Member Avatar
deepak690
Newbie Poster
5 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

friends i am trying but not able to it...can anyone pls do this...........

Member Avatar
ChrisHunter
Practically a Master Poster
625 posts since Feb 2011
Reputation Points: 120 [?]
Q&As Helped to Solve: 69 [?]
Skill Endorsements: 15 [?]
Featured
 
0
 

so have you just found this on the internet and going to submit it as your project for collage ?

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
0
 

What is the first error you get from the compiler?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: