尝试从DataGrid更新SQL表 [英] Trying to update sql table from datagrid

查看:74
本文介绍了尝试从DataGrid更新SQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做我的第一个C#SQL项目.一个简单的支票簿寄存器.

我提到了CodeProject文章:

使用DataGrid控件:使用DataGrid控件 [
我已经研究了3天,但我只是不明白我所看到的.

有人可以帮忙吗?
谢谢.
马克


我在Form1.cs中的代码:

I am working on my first C# SQL project. A simple checkbook register.

I referred to the CodeProject article:

Using the DataGrid Control: Using the DataGrid Control[^]

I added a datagridview control to my form and set the data source as my checkbook register in SQL Express.

I am able to see all the checkbook entries when I run the form.

My first attempt at updating the sql table is generating a compile error.

The error is:
cannot convert from ''System.Data.DataSet'' to ''FirstCheckBookInSQL.CheckBookManagementDataSet.CheckbookUSBPersonalDataTable''

I''ve been researching this for 3 days, but I''m just not making sense of what I am seeing.

Can someone help please!
Thank you.
Mark


My code in Form1.cs:

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 FirstCheckBookInSQL
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'checkBookManagementDataSet.CheckbookUSBPersonal' table. You can move, or remove it, as needed.
            this.checkbookUSBPersonalTableAdapter.Fill(this.checkBookManagementDataSet.CheckbookUSBPersonal);
        }
        private void TBDbutton_Click(object sender, EventArgs e)
        {
            DataSet myChangedDataSet = this.checkBookManagementDataSet.GetChanges();
            if (myChangedDataSet != null)
            {
                // get how many rows changed


<big>// this is the line of code I am getting the error on:
                int modifiedRows = this.checkbookUSBPersonalTableAdapter.Update(myChangedDataSet);</big>
                //MessageBox.Show("Database has been updated successfully: " +
                //modifiedRows + " Modified row(s) ", "Success");
                this.checkBookManagementDataSet.AcceptChanges();
                myChangedDataSet.AcceptChanges();
            }
            MessageBox.Show("no data changed");
        }
    }
}

推荐答案

我怀疑您想和文章作者谈谈,文章下面有一个论坛.我看不到为什么基于此代码在项目中有一个名为CheckbookUSBPersonalDataTable的对象,显然是的,还有与此相关的表适配器.
I suspect you want to talk to the article author, there''s a forum for that under the article. I can''t see why you have an object called CheckbookUSBPersonalDataTable in your project based on this code, it apparently you do, and a table adapter to go with it.


您是否尝试过此方法?

have you tried this?

int modifiedRows = this.checkbookUSBPersonalTableAdapter.Update(myChangedDataSet.Tables[0]);


这篇关于尝试从DataGrid更新SQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆