使用自动递增字段更新MySQL中的数据 [英] Update data in MySQL with auto incrementing field

查看:92
本文介绍了使用自动递增字段更新MySQL中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#windows窗体构建一个简单的MySQL系统。

I am using c# windows form to build a simple system with MySQL.

我有两个表,定义如下:

I have two tables, defined as follows:


  • 问题

    • questionNum(varchar,pk,not null)
    • questionDes
    • 提示

      < li style =""> answerId(INT,pk,not null,auto increment)
    • answerIncro
    • answerDes
    • eQuestionsNum(fk)

    两种形式:


    • form1( textbox) - questionNum + questionDes + answerDes'按钮'形成2
    • form2(文本框) - questionNum?+提示+ answerIncro'按钮'来完成

    form1 :我知道如何将数据插入问答表,还保存questionNum并转移到form2。

    form1 : I know how to insert data into question and answer table, and also save the questionNum and transfer to form2.

    form2 :我已将数据更新到问题表,但我不知道如何更新答案表(因为answerId是自动增量)。

    form2 : I have updated the data to question table, but I do not know how to update the answer tables (because the answerId is auto increment).

    如果form2上没有questionNum文本框,如何将form2上的数据添加到Form1的questionNum

    and if there is no questionNum textbox on form2, how to add data on form2 to the questionNum of Form1

    有什么建议吗?

    这里我的表格代码2:

    使用System;

    使用System.Collections.Generic;

    使用System.ComponentModel;

    使用System.Data;

    使用System.Drawing;

    使用System.Linq;

    使用System.Text;

    使用System.Text;
    使用System.Threading.Tasks;

    使用System.Windows.Forms;

    使用MySql.Data.MySqlClient;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using MySql.Data.MySqlClient;

    推荐答案

    检查MySQL的 LAST_INSERT_ID ()。类似于MSSQL的SCOPE_IDENTITY()

    Check into LAST_INSERT_ID() for MySQL. Works similar to SCOPE_IDENTITY() for MSSQL

    这篇关于使用自动递增字段更新MySQL中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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