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.SqlClient;
namespace Student
{
public partial class DPMUpd : Form
{
public DPMUpd()
{
InitializeComponent();
}
private string dpmstrconn;
private SqlConnection dpmconn;
private SqlDataAdapter dpmcomm;
private SqlCommandBuilder dmpcommbd;
private string connstr = "Data Source=WWW-F9EEA54BDCA;Initial Catalog=STUDENT;User ID=sa;Pwd=jxlsqd;Integrated Security=False";
private DataSet dpmset = new DataSet(); private void DPMUpd_Load(object sender, EventArgs e)
{
dpmstrconn = "select * from DEPARTMENT";
dpmconn = new SqlConnection(connstr);
dpmcomm = new SqlDataAdapter(dpmstrconn, dpmconn);
dpmset.Clear(); dpmcomm.Fill(dpmset, "DEPARTMENT");
datgd.DataSource = dpmset.Tables[0]; }
private void button2_Click(object sender, EventArgs e)
{
int row = this.datgd.CurrentCell.RowNumber;
this.datgd.CurrentCell = new DataGridCell(row + 1, 0);
if (dpmset.HasChanges())
{
this.dpmconn = new SqlConnection(this.connstr);
this.dpmcomm = new SqlDataAdapter(this.dpmstrconn, this.dpmconn);
dmpcommbd = new SqlCommandBuilder(dpmcomm);
// datgd.Update(this.dpmset.GetChanges(), "DEPARTMENT");
dpmset.AcceptChanges();
MessageBox.Show("信息修改成功", "消息");
}
}
private void button1_Click(object sender, EventArgs e)
{
dpmstrconn = "select * from DEPARTMENT where DEPARTMENT =" + "'" + this.txtnam.Text.ToString().Trim() + "'";
dpmconn = new SqlConnection(connstr);
dpmcomm = new SqlDataAdapter(dpmstrconn, dpmconn);
dpmset.Clear(); dpmcomm.Fill(dpmset, "DEPARTMENT");
datgd.DataSource = dpmset.Tables[0]; }
private void button3_Click(object sender, EventArgs e)
{
int rowNumber = this.datgd.CurrentCell.RowNumber; this.dpmset.Tables[0].Rows[rowNumber].Delete();
this.dpmconn = new SqlConnection(this.connstr);
dpmcomm = new SqlDataAdapter("", dpmconn);
dmpcommbd = new SqlCommandBuilder(dpmcomm);
this.datgd.Update(dpmset.GetChanges(), "DEPARTMENT");
MessageBox.Show("信息删除成功!", "消息");
}
this.datgd.Update(dpmset.GetChanges(), "DEPARTMENT"); 以上这两句每次运行都会提示updete方法没有采用2个参数的重载! 请帮忙看看 在线等~
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Student
{
public partial class DPMUpd : Form
{
public DPMUpd()
{
InitializeComponent();
}
private string dpmstrconn;
private SqlConnection dpmconn;
private SqlDataAdapter dpmcomm;
private SqlCommandBuilder dmpcommbd;
private string connstr = "Data Source=WWW-F9EEA54BDCA;Initial Catalog=STUDENT;User ID=sa;Pwd=jxlsqd;Integrated Security=False";
private DataSet dpmset = new DataSet(); private void DPMUpd_Load(object sender, EventArgs e)
{
dpmstrconn = "select * from DEPARTMENT";
dpmconn = new SqlConnection(connstr);
dpmcomm = new SqlDataAdapter(dpmstrconn, dpmconn);
dpmset.Clear(); dpmcomm.Fill(dpmset, "DEPARTMENT");
datgd.DataSource = dpmset.Tables[0]; }
private void button2_Click(object sender, EventArgs e)
{
int row = this.datgd.CurrentCell.RowNumber;
this.datgd.CurrentCell = new DataGridCell(row + 1, 0);
if (dpmset.HasChanges())
{
this.dpmconn = new SqlConnection(this.connstr);
this.dpmcomm = new SqlDataAdapter(this.dpmstrconn, this.dpmconn);
dmpcommbd = new SqlCommandBuilder(dpmcomm);
// datgd.Update(this.dpmset.GetChanges(), "DEPARTMENT");
dpmset.AcceptChanges();
MessageBox.Show("信息修改成功", "消息");
}
}
private void button1_Click(object sender, EventArgs e)
{
dpmstrconn = "select * from DEPARTMENT where DEPARTMENT =" + "'" + this.txtnam.Text.ToString().Trim() + "'";
dpmconn = new SqlConnection(connstr);
dpmcomm = new SqlDataAdapter(dpmstrconn, dpmconn);
dpmset.Clear(); dpmcomm.Fill(dpmset, "DEPARTMENT");
datgd.DataSource = dpmset.Tables[0]; }
private void button3_Click(object sender, EventArgs e)
{
int rowNumber = this.datgd.CurrentCell.RowNumber; this.dpmset.Tables[0].Rows[rowNumber].Delete();
this.dpmconn = new SqlConnection(this.connstr);
dpmcomm = new SqlDataAdapter("", dpmconn);
dmpcommbd = new SqlCommandBuilder(dpmcomm);
this.datgd.Update(dpmset.GetChanges(), "DEPARTMENT");
MessageBox.Show("信息删除成功!", "消息");
}
this.datgd.Update(dpmset.GetChanges(), "DEPARTMENT"); 以上这两句每次运行都会提示updete方法没有采用2个参数的重载! 请帮忙看看 在线等~
你是想要用SplDataAdapter的Update方法吧