111,119
社区成员
发帖
与我相关
我的任务
分享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 WindowsApplication3
{
public partial class Form1 : Form
{
SqlConnection con;
SqlDataAdapter da;
DataTable dt;
public Form1()
{
InitializeComponent();
con = new SqlConnection("Server=.;Integrated Security=True;Database=pubs");
dt = new DataTable();
}
private void Form1_Load(object sender, EventArgs e)
{
da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select * from jobs", con);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
da.Fill(dt);
this.bindingSource1.DataSource = dt;
this.dataGridView1.DataSource = bindingSource1;
}
private void toolStripBtnSave_Click(object sender, EventArgs e)
{
//更新
if (dt == null)
{
MessageBox.Show("dt为null");
return;
}
this.Validate();//这个很重要..没有更新不了.
da.Update(dt);
dt.AcceptChanges();
}
}
}