尝试从DataGrid更新SQL表

尝试从DataGrid更新SQL表

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

问题描述

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

我提到了CodeProject文章:

使用DataGrid控件:使用DataGrid控件 [ ^ ]

我在表单中添加了datagridview控件,并将数据源设置为SQL Express中我的支票簿寄存器.

运行表单时,我能够看到所有支票簿条目.

我第一次尝试更新sql表时会产生编译错误.

错误是:
无法从"System.Data.DataSet"转换为"FirstCheckBookInSQL.CheckBookManagementDataSet.CheckbookUSBPersonalDataTable"

我已经研究了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");
        }
    }
}

推荐答案


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


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

08-23 21:15