c #Windows Form Application将数据添加到具有关系的表中

时间:2022-02-18 14:46:53

I'm new to c# Windows Form Application and I'm having a problem in adding/inserting data to SQL DB that has relationship between tables. My question is, Will the relation between the tables function in C# Windows Form Application?

我是c#Windows Form Application的新手,我在向表中有关系的SQL DB添加/插入数据时遇到了问题。我的问题是,表格之间的关系是否会在C#Windows窗体应用程序中起作用?

This is how my DB looks

这就是我的数据库的外观

c #Windows Form Application将数据添加到具有关系的表中

I'm looking for a way to add data to the Article table and Body table where Artcle.body_id will pupolate accordingly. The same as MVC. Thanx

我正在寻找一种方法来将数据添加到Article表和Body表中,其中Artcle.body_id将相应地进行伪装。与MVC相同。感谢名单

2 个解决方案

#1


0  

You can define your custom method to update or insert the values.

您可以定义自定义方法以更新或插入值。

#2


0  

Got the code now. Hope this will help others in the future.

现在有了代码。希望这将有助于未来的其他人。

   private void buttonCreateSubmit_Click(object sender, EventArgs e)
    {
        Body body = new Body
        {
            body_content = richTextBoxBody.Text
        };

        tnDBase.AddToBodies(body);
        tnDBase.SaveChanges();

        var genid = tnDBase.Genres.Single(g => g.genre_name == comboBoxGenre.Text);

        Article article = new Article()
        {
            article_name = textBoxTitle.Text,
            genre_id = genid.genre_id,
            status_id = 3,
            body_id = body.body_id
        };

        tnDBase.AddToArticles(article);
        tnDBase.SaveChanges();
     }

#1


0  

You can define your custom method to update or insert the values.

您可以定义自定义方法以更新或插入值。

#2


0  

Got the code now. Hope this will help others in the future.

现在有了代码。希望这将有助于未来的其他人。

   private void buttonCreateSubmit_Click(object sender, EventArgs e)
    {
        Body body = new Body
        {
            body_content = richTextBoxBody.Text
        };

        tnDBase.AddToBodies(body);
        tnDBase.SaveChanges();

        var genid = tnDBase.Genres.Single(g => g.genre_name == comboBoxGenre.Text);

        Article article = new Article()
        {
            article_name = textBoxTitle.Text,
            genre_id = genid.genre_id,
            status_id = 3,
            body_id = body.body_id
        };

        tnDBase.AddToArticles(article);
        tnDBase.SaveChanges();
     }