首页上一页 1 下一页尾页 4 条记录 1/1页
C#从入门到精通的15.6.3的例子调不出来
发表在C#图书答疑
2012-11-28
是否精华
是
否
版块置顶:
是
否
你好,《C#从入门到精通》第二版的15.6.3 更新数据源部分
我的代码和光盘上的一样,为什么我做的下面几个文本框控件没有内容显示呢?而且在上面正行也不能选中,只能选中某一个单元格,并且在上部选中的时候,下面的文本框控件不显示选中的内容,并且双击单元格的时候,编辑器还会报错,提示“输入的参数有问题”,请问这是为什么?论坛传不了图啊
我的代码如下:
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Update数据源
{
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=.;database=db_15;uid=sa;pwd=");
SqlCommand cmd = new SqlCommand("select * from tb_command", conn);
sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
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["姓名"] = txtName.Text.Trim();
dr["性别"] = this.txtSex.Text.Trim();
dr["年龄"] = this.txtAge.Text.Trim();
dr["奖金"] = this.txtJJ.Text.Trim();
SqlCommandBuilder cmdbuilder = 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();
txtSex.Text = dataGridView1.SelectedCells[2].Value.ToString();
txtAge.Text = dataGridView1.SelectedCells[3].Value.ToString();
txtJJ.Text = dataGridView1.SelectedCells[4].Value.ToString();
}
}
}
我的代码和光盘上的一样,为什么我做的下面几个文本框控件没有内容显示呢?而且在上面正行也不能选中,只能选中某一个单元格,并且在上部选中的时候,下面的文本框控件不显示选中的内容,并且双击单元格的时候,编辑器还会报错,提示“输入的参数有问题”,请问这是为什么?论坛传不了图啊
我的代码如下:
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Update数据源
{
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=.;database=db_15;uid=sa;pwd=");
SqlCommand cmd = new SqlCommand("select * from tb_command", conn);
sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
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["姓名"] = txtName.Text.Trim();
dr["性别"] = this.txtSex.Text.Trim();
dr["年龄"] = this.txtAge.Text.Trim();
dr["奖金"] = this.txtJJ.Text.Trim();
SqlCommandBuilder cmdbuilder = 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();
txtSex.Text = dataGridView1.SelectedCells[2].Value.ToString();
txtAge.Text = dataGridView1.SelectedCells[3].Value.ToString();
txtJJ.Text = dataGridView1.SelectedCells[4].Value.ToString();
}
}
}