用dataGridView显示数据后,在它里面修改值 修改完以后通过一个按钮把修改后的值更新到数据库中
应该怎么写呢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 datagridview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataSet ds = new DataSet();
private SqlDataAdapter adapter;
private void Form1_Load(object sender, EventArgs e)
{
string sql = "select * from tur";
string con = "Data Source=.;database=Sdyy;uid=sa";
SqlConnection conn= new SqlConnection(con);
conn.Open();
adapter = new SqlDataAdapter(sql,conn);
adapter.Fill(ds,"tur");
this.dataGridView1.DataSource=ds.Tables[0];
conn.Close();
} private void button1_Click(object sender, EventArgs e)
{
SqlCommandBuilder build = new SqlCommandBuilder(adapter);
adapter.Update(ds,"tur");
} private void freash_Click(object sender, EventArgs e)
{ }
}
}我选中其中任意一个单元格的值然后点保存就会更新到数据库中去~ 要怎么做呢? 现在我上面的代码报这个错:
请问要实现这样的功能应该怎么写呢 彻底崩溃了~被ADO给整晕了 在线等
应该怎么写呢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 datagridview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataSet ds = new DataSet();
private SqlDataAdapter adapter;
private void Form1_Load(object sender, EventArgs e)
{
string sql = "select * from tur";
string con = "Data Source=.;database=Sdyy;uid=sa";
SqlConnection conn= new SqlConnection(con);
conn.Open();
adapter = new SqlDataAdapter(sql,conn);
adapter.Fill(ds,"tur");
this.dataGridView1.DataSource=ds.Tables[0];
conn.Close();
} private void button1_Click(object sender, EventArgs e)
{
SqlCommandBuilder build = new SqlCommandBuilder(adapter);
adapter.Update(ds,"tur");
} private void freash_Click(object sender, EventArgs e)
{ }
}
}我选中其中任意一个单元格的值然后点保存就会更新到数据库中去~ 要怎么做呢? 现在我上面的代码报这个错:
请问要实现这样的功能应该怎么写呢 彻底崩溃了~被ADO给整晕了 在线等
解决方案 »
- C#利用WMI如何识别本地连接并只修改本地连接的IP?
- C# TcpListener如何同时接收多个客户端的数据。
- 关于 override WndProc 的小问题
- 关于网站切换模版的资料问题,求助了。
- InvokeRequired是什么意思
- 如何在程序运行时拖动界面上的控件到另一个位置
- 高手请进,常用问题
- 请教一个采集网页内容的问题,目标站有防采集机制
- 关于ADO.NET设计模型上的困惑?
- DataSet查询数据速度问题
- 请问怎么能让【Label】里的文字 分行显示!!谢谢!
- 我有两个窗体Form1 和Form2 其中Form1中有个Panel 我想在Form2中操作Form1里的Panel 这样怎么办呢?
SqlCommand myCmd = new SqlCommand("select * from tur",con);
adapter.SelectCommand = myCmd;
难道你们都不知道如果sa用户的密码为空pwd=''是可以省略的么?
居然还这么多人人云亦云