如何设置外键

编程入门 行业动态 更新时间:2024-10-27 04:36:04
本文介绍了如何设置外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两张桌子艺术家和艺术家。 artistId是artist表中的主键,它是arts table中的外键。我使用存储过程来插入数据。第一个艺术家登录然后艺术信息页面显示艺术家插入艺术信息。我希望艺术家ID也插入艺术表插入艺术信息。我试着这样做: 存储过程: 如果存在(从艺术家中选择artistId) 插入arts(name,description,artistId)值(@ name,@ description,@ artistId) asp代码:

cmd.Parameters.AddWithValue( @ name,txtname。 Text ); cmd.Parameters.AddWithValue( @ category,ddlcategory.SelectedValue);

它不工作。 我是存储过程的新手。请帮我获取外键值。还有其他方法吗?

解决方案

您的存储过程中有3个参数,需要设置所有参数值。 当艺术家登录系统时,您可以从数据库中获取artistId并保留该值。

cmd.Parameters.AddWithValue( @名,txtname.Text); cmd.Parameters.AddWithValue( @ category,ddlcategory.SelectedValue); cmd.Parameters.AddWithValue( @ artistId,artistId);

I have two tables artist and arts. artistId is a primary key in artist table and it is the foreign key in arts table.I am using stored procedure to insert data. first artist log in and then art info page is displayed where artist insert art info.I want that artist id to get inserted in arts table also when he inserts art info.I tried this as: stored procedure: if exists(select artistId from artist) insert into arts(name,description,artistId) values(@name,@description,@artistId) asp code:

cmd.Parameters.AddWithValue("@name",txtname.Text); cmd.Parameters.AddWithValue("@category",ddlcategory.SelectedValue);

It is not working. I am new to stored procedure.Please help me to get the foreign key value.Or is there any other way?

解决方案

you have 3 parameters in your stored procedure, need to set all the parameter values. when artist login to system you can get the artistId from the database and keep that value.

cmd.Parameters.AddWithValue("@name",txtname.Text); cmd.Parameters.AddWithValue("@category",ddlcategory.SelectedValue); cmd.Parameters.AddWithValue("@artistId",artistId);

更多推荐

如何设置外键

本文发布于:2023-10-14 21:37:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492284.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何设置

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!