C#通过Datagridview来删除肯更新SQL数据库

eric_feng666 eric_feng666 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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 Update_SQL
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private SqlConnection con = null;
private DataSet ds = new DataSet();
private SqlDataAdapter myda = null;
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=localhost;database=AlumManager;user=sa;pwd=sql";
string selectSQL = "select * from test ";
SqlDataAdapter myda = new SqlDataAdapter(selectSQL, con);
myda.Fill(ds,"test");
this.dataGridView1.DataSource = ds.Tables["test"];
}

private void Update_btn_Click(object sender, EventArgs e)
{
SqlCommandBuilder SCB = new SqlCommandBuilder(myda);
myda.Update(ds, "test");
}

private void Del_btn_Click(object sender, EventArgs e)
{
dataGridView1.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex);
SqlCommandBuilder SCB = new SqlCommandBuilder(myda);
myda.Update(ds, "test");

}
}
}
...全文

相关推荐

评论 21
收藏 已收藏
分享
返回顶部
eric_feng666
C# 111,130 成员 642,541 内容