[已解决问题] dataset更新数据库
提问时间: 2008-05-16 11:20
悬赏分:10 浏览:236 次

那位大哥有DATASET更新数据库的代码   DATA的表结构跟数据库里的一个表的结构是一样的

    帮帮忙啊   分不够可以加


提问者:浩浩 - 初学一级
所有回答(2)
用适配器可以更新,更新之前要先定义好insertcommand和参数设置。适配器好像有一个update方法是可以了。
2个月前   回答者:李.net - 小虾三级
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace Example_2
{
/// <summary>
/// frmIssueBooks 的摘要说明。
/// </summary>
public class frmIssueBooks : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnBorrowBook;
private System.Windows.Forms.GroupBox grpInsertDetails;
private System.Windows.Forms.TextBox txtAuthor;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtBookAccessCode;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtStdID;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtStdName;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.GroupBox grpBookDetails;
private System.Windows.Forms.DataGrid dbgBooksDt;
private System.Windows.Forms.ComboBox cboBookName;
private System.Windows.Forms.TextBox txtIssueDate;
private System.Windows.Forms.Label label6;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

private SqlDataAdapter objSqlDataAdapter,objBkDtAdapt;
private SqlConnection objSqlConn;
private DataSet objDataSet,objBkDtDs;
private SqlParameter objParam;

public frmIssueBooks()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// 
private bool ValidateFields()
{
bool returnValue=true;

//检查图书访问码是否为空
if(this.txtBookAccessCode.Text.Trim()==string.Empty)
{
MessageBox.Show("提供完整的详细信息");
return false;
}
else
{
//检查学生姓名是否包含任何数字数
1个月前   回答者:ڜǺ☻ďų - 菜鸟二级
评论
2个月前   浩浩 :
    public static void updatadata(DataSet srcDS, string tableName, string dsTable)
    {
        DataSet ds = new DataSet();
        SqlConnection Connection = new SqlConnection(connectionString);
        Connection.Open();
        SqlDataAdapter da =new SqlDataAdapter("select * from " + tableName + "", Connection);
        SqlCommandBuilder sqlCmdBuilder = new SqlCommandBuilder(da);
        da.Update(srcDS, dsTable);
        srcDS.AcceptChanges();
    }



那里错了  这个方法传3个参数  一个是DATASET一个是要插入的表名
另一个是  DATASET里的表名
   您需要登录以后才能回答!
我的问题    我要提问


快到期问题

> 问题排行榜

有不合适内容,建议去除