我有两张桌子艺术家和艺术家。 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);更多推荐
如何设置外键
发布评论