如何在不同的表中插入单个Windows窗体的值 [英] How to insert values of a single windows form in diffrent tables

查看:64
本文介绍了如何在不同的表中插入单个Windows窗体的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不同的表中插入单个Windows窗体的值.
在我的Windows窗体中有多个文本框,我想在两个表中另存一些文本框值.使用单个sava按钮.

How to insert values of a single windows form in diffrent tables.
In my windows form there are mutliple text box, I want to save some text box value in differnt in two tables. using single sava button.

推荐答案

假设这些是您正在讨论的数据库表,只需创建两个SQLCommand对象并在每个表中使用一个即可:

Assuming these are database tables you are talking about, just create two SQLCommand objects and use one per table:

using (SqlConnection con = new SqlConnection(connectionString))
    {
    con.Open();
    using (SqlCommand com1 = new SqlCommand("INSERT INTO myTableOne (myColumn1, myColumn2) VALUES (@C1, @C2)",con))
        {
        com1.Parameters.AddWithValue("@C1", myTextBoxC1);
        com1.Parameters.AddWithValue("@C2", myTextBoxC2);
        com1.ExecuteNonQuery();
        }
    using (SqlCommand com2 = new SqlCommand("INSERT INTO myTableType (myColumnOther1, myColumnOther2) VALUES (@OC1, @OC2)",con))
        {
        com2.Parameters.AddWithValue("@OC1", myOtherTextBoxC1);
        com2.Parameters.AddWithValue("@OC2", myOtherTextBoxC2);
        com2.ExecuteNonQuery();
        }
    }

如有必要,可以将它们括在SQL TRANSACTION中.

If necessary, you can enclose these in an SQL TRANSACTION.


您需要具有一个存储过程,该存储过程接受所有值作为参数并将其保存到相应的表中.您也可以使用多个.在网上搜索基本的ADO.Net示例,您应该可以弄清楚.
You need to have a stored procedure that accepts all the values as parameters and saves them to respective tables. You can also use multiple. Search for basic ADO.Net example on web and you should be able to figure it out.


这篇关于如何在不同的表中插入单个Windows窗体的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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