首页上一页 1 下一页尾页 1 条记录 1/1页
17章练习五datagriw输入数据出错
发表在C#图书答疑
2014-11-10
是否精华
是
否
版块置顶:
是
否
[strong]"对于不返回任何键列信息的 SelectCommand,不支持 UpdateCommand 的动态 SQL 生成。"}
[/strong]
这个问题要怎么处理?
请编写一下完整代码
我现在的代码是这样的:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _123456
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
SqlDataAdapter sda = null;
public DataTable GetDataTable(string strSql)
{
string strConn = "Server=PC-201207261042\\SQLEXPRESS;Integrated Security=SSPI;database = 123456";
SqlConnection sqlConn = new SqlConnection(strConn);
try
{
sda = new SqlDataAdapter(strSql, sqlConn);
new SqlCommandBuilder(sda);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
private void Form4_Load(object sender, EventArgs e)
{
shiborBindingSource.DataSource = GetDataTable("Select * From shibor");
dataGridView1.DataSource = shiborBindingSource;
// TODO: 这行代码将数据加载到表“_123456DataSet.shibor”中。您可以根据需要移动或删除它。
//this.shiborTableAdapter.Fill(this._123456DataSet.shibor);
//this.WindowState = FormWindowState.Maximized;
}
private void Form4_MdiChildActivate(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
dataGridView1.EndEdit();
shiborBindingSource.EndEdit();
DataTable dt = shiborBindingSource.DataSource as DataTable;
try
{
if (sda.Update(dt) > 0)
{
MessageBox.Show("保存成功!", "信息提示");
}
else
{
MessageBox.Show("保存失败或数据未发生任何改变!", "信息提示");
}
}
catch (Exception ex)
{
throw ex;
}
return;
}
}
}
[/strong]
这个问题要怎么处理?
请编写一下完整代码
我现在的代码是这样的:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _123456
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
SqlDataAdapter sda = null;
public DataTable GetDataTable(string strSql)
{
string strConn = "Server=PC-201207261042\\SQLEXPRESS;Integrated Security=SSPI;database = 123456";
SqlConnection sqlConn = new SqlConnection(strConn);
try
{
sda = new SqlDataAdapter(strSql, sqlConn);
new SqlCommandBuilder(sda);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
private void Form4_Load(object sender, EventArgs e)
{
shiborBindingSource.DataSource = GetDataTable("Select * From shibor");
dataGridView1.DataSource = shiborBindingSource;
// TODO: 这行代码将数据加载到表“_123456DataSet.shibor”中。您可以根据需要移动或删除它。
//this.shiborTableAdapter.Fill(this._123456DataSet.shibor);
//this.WindowState = FormWindowState.Maximized;
}
private void Form4_MdiChildActivate(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
dataGridView1.EndEdit();
shiborBindingSource.EndEdit();
DataTable dt = shiborBindingSource.DataSource as DataTable;
try
{
if (sda.Update(dt) > 0)
{
MessageBox.Show("保存成功!", "信息提示");
}
else
{
MessageBox.Show("保存失败或数据未发生任何改变!", "信息提示");
}
}
catch (Exception ex)
{
throw ex;
}
return;
}
}
}