Click here to Skip to main content
15,886,861 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi sir/mam,
I have tried above subject in MS VS 2010 but i couldn't succeed in that so i have attached my code. Please rectify and send to me,so that it will be very useful for me in learning this project completely.kindly rectify my mistakes in the code 2 get output.

i hav created id , name , age , phone , email in database , its enough .




C#
using System;
using System.Collections.Generic; 
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using CrystalDecisions.CrystalReports.Engine;


namespace createEmp
{
public partial class Form1 : Form
{
static string connectionString = "Data Source=DIVYA-PC;Initial Catalog=emp;Integrated Security=True";

SqlConnection con = new SqlConnection(connectionString);


public Form1()
{
InitializeComponent();
GetData();
}

private void Form1_Load(object sender, EventArgs e)
{

// this.employeeTableAdapter.Fill(this.empDataSet.employee);

SqlConnection connection = new SqlConnection("Data Source=DIVYA-PC;Initial Catalog=emp;Integrated Security=True");
SqlCommand cmd = new SqlCommand("Select top 10 * From employee", connection);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);

DataSet dataset = new DataSet();
adapter.Fill(dataset, "employee");
// ReportDocument employeeReport = new ReportDocument();
//CustomerReport.Load(Server.MapPath("employeeReport.rpt"));
//CustomerReport.SetDataSource(dataset.Tables["employee"]);
// CrystalReportViewer1.ReportSource = employeeReport;
//CrystalReportViewer1.DataBind();

}

private void btninsert_Click(object sender, EventArgs e)
{
string sql = "Insert into employee(id,name,age,phone,email)";
sql += "values('" + txtid.Text + "','" + txtname.Text + "','" + txtage.Text + "','" + txtphone.Text + "','" + txtemail.Text + "' )";
if (con.State != System.Data.ConnectionState.Open)
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);

cmd.ExecuteNonQuery();

MessageBox.Show("Record committed");
}
else
{
con.Close();
}


}

private void GetData()
{

string sql = "select * from employee ";
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
dgvdataGridView1.DataSource = dt;
}



private void btnupdate_Click(object sender, EventArgs e)
{
string sql = "Update employee set name='" + txtname.Text + "'";
sql += "where id='" + txtid.Text + "',age='" + txtage.Text + "',phone='" + txtphone.Text + "',email='" + txtname.Text + "'";
if (con.State != System.Data.ConnectionState.Open)
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();

MessageBox.Show("Record update Id No:- " + txtid.Text);
GetData();
}

else
{
con.Close();
}
}





private void button3_Click(object sender, EventArgs e)
{
string sql = "delete employee set name='" + txtname.Text + "'";
sql += "where id='" + txtid.Text + "',age='" + txtage.Text + "',phone='" + txtphone.Text + "',email='" + txtname.Text + "'";
if (con.State != System.Data.ConnectionState.Open)
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();

MessageBox.Show("Record delete Id No:- " + txtid.Text);
GetData();
}
else
{
con.Close();
}

}

private void dgvdataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int i;
i = dgvdataGridView1.SelectedCells[0].RowIndex;
txtid.Text = dgvdataGridView1.Rows[i].Cells[0].Value.ToString();
txtname.Text = dgvdataGridView1.Rows[i].Cells[1].Value.ToString();
txtage.Text = dgvdataGridView1.Rows[i].Cells[2].Value.ToString();
txtphone.Text = dgvdataGridView1.Rows[i].Cells[3].Value.ToString();
txtemail.Text = dgvdataGridView1.Rows[i].Cells[4].Value.ToString();
txtid.Text = "";
txtname.Text = "";
txtage.Text = "";
txtphone.Text = "";
txtemail.Text = "";

}

}
}
Posted
Updated 24-Apr-13 2:47am
v2
Comments
[no name] 24-Apr-13 6:53am    
"but i couldn't succeed" does not mean anything to anyone but you. You need to clear describe the problem that you are having. No one is going to complete your project for you, especially when you do not describe what your program is actually doing and what you expect it to do.
Sebastian T Xavier 24-Apr-13 8:46am    
please don't dump all your code. at lease use formatting

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900