已有56人关注
老师来帮下忙 C#从入门到精通第3版 15.6.3 实例位置\TM\sl\15\8
发表在C#图书答疑 2015-05-23
是否精华
版块置顶:
我把你们的代码稍微改动了一下 但是出错了 下面是代码
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Test08
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
DataSet ds;
SqlDataAdapter sda;

private void Form1_Load(object sender, EventArgs e)
{
conn = new SqlConnection("server=P5ZT4CYV41AC7L8;database=test_db;Trusted_Connection=SSPI");
SqlCommand cmd = new SqlCommand("select * from TABLE1", conn);
sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "cs");
dataGridView1.DataSource = ds.Tables[0];
}
private void button1_Click(object sender, EventArgs e)
{

DataTable dt = ds.Tables["cs"];   //这里出错了 
sda.FillSchema(dt, SchemaType.Mapped);
DataRow dr = dt.Rows.Find(txtNo.Text);
dr["name"] = txtName.Text.Trim();

SqlCommandBuilder cmdbuider = new SqlCommandBuilder(sda);
sda.Update(dt);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
txtNo.Text = dataGridView1.SelectedCells[0].Value.ToString();
txtName.Text = dataGridView1.SelectedCells[1].Value.ToString();

}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}

[img src=null/img][img src=null/img]
分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2015-05-25
沙发
读者朋友:
    您好,把Form1_Load事件中的DataSet ds = new DataSet();修改为ds = new DataSet();
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照