Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 .
 

 

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 24-Apr-13 1:01am
Edited 24-Apr-13 3:47am
(no name)15.4K
v2
Comments
ThePhantomUpvoter at 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 at 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)

  Print Answers RSS
0 OriginalGriff 6,769
1 Sergey Alexandrovich Kryukov 6,338
2 DamithSL 5,408
3 Manas Bhardwaj 4,816
4 Maciej Los 4,195


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 24 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100