没能达到理想效果~~理想效果应该如下
:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 通讯录管理系统
{
public partial class PerManage : Form
{
PersonManage cmg = new PersonManage();
public PerManage()
{
InitializeComponent();
} private void InitDgv()
{
DataSet ds = new DataSet();
ds = cmg.PerSelect();
dataGridView1.DataSource = ds.Tables[0]; } private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
try
{
textBox1.Text = Convert.ToString(dataGridView1.CurrentRow.Cells[1].Value);
textBox2.Text = Convert.ToString(dataGridView1.CurrentRow.Cells[2].Value);
}
catch
{
MessageBox.Show("选择越界");
}
} private void button1_Click(object sender, EventArgs e)
{
//cmg.ID = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
cmg.Name = textBox1.Text.Trim();
cmg.Tel = textBox2.Text.Trim();
if (cmg.PerUpdate())
{
MessageBox.Show("修改成功!");
InitDgv(); }
else
{
MessageBox.Show("修改失败\n\n请检测输入数据的正确性!");
} } private void button2_Click(object sender, EventArgs e)
{
//cmg.ID = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
if (cmg.PerDel())
{
MessageBox.Show("删除成功");
InitDgv();
}
else
{
MessageBox.Show("删除失败");
}
}
}
}classmanege类
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace 通讯录管理系统
{
class ClassesManage
{ #region ClassID ClassName OrderBy 定义全局变量
/// <summary>
/// 定义变量
/// </summary>
public int ClassID = 0;
public string ClassName = "";
public int OrderBy = 0;
#endregion #region bool ClsAdd 类别添加
/// <summary>
/// 添加类别
/// </summary>
/// <returns></returns>
public bool ClsAdd()
{ SqlConnection conn = new SqlConnection(dbBase.ConStr);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into Classes (ClassName,orderby) values ('" + ClassName + "'," + OrderBy + ")";
try
{
conn.Open();
cmd.ExecuteNonQuery();
return true; }
catch
{
return false; }
finally
{
conn.Close();
}
}
#endregion #region bool ClsUpdate 修改类别
/// <summary>
/// 修改类别
/// </summary>
/// <returns></returns>
public bool ClsUpdate()
{
SqlConnection conn = new SqlConnection(dbBase.ConStr);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "update classes set ClassName='" + ClassName + "',orderby=" + OrderBy + " where ClassID=" + ClassID;
try
{
conn.Open();
cmd.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
conn.Close();
}
}
#endregion #region bool ClsDel 删除类别
/// <summary>
/// 删除类别
/// </summary>
/// <returns></returns>
public bool ClsDel()
{
SqlConnection conn=new SqlConnection(dbBase.ConStr);
SqlCommand cmd=conn.CreateCommand();
cmd.CommandText="delete from classes where classid="+ClassID;
try
{
conn.Open();
cmd.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
conn.Close();
}
}
#endregion #region DataSet ClsSelect 查询类别表中的内容
/// <summary>
/// 查询类别表中的内容,返回dataset
/// </summary>
/// <returns></returns>
public DataSet ClsSelect()
{
SqlDataAdapter DApt=new SqlDataAdapter("select classid as 类别编号,className as 类别名称,orderby as 排序 from Classes order by orderby asc",dbBase.ConStr);
DataSet ds=new DataSet();
DApt.Fill(ds);
return ds;
}
#endregion }
}在这里感谢各位大大了~~~有QQ的请留下~~顺便~
而personnel表,不可以显示,更不要说修改,删除了...
我是对应写的...不知道为什么...