使用ASP.NET关键字'join'附近的语法不正确

编程入门 行业动态 更新时间:2024-10-25 14:24:46
本文介绍了使用ASP.NET关键字'join'附近的语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请注意我仍然是数据库的初学者,但愿意学习。这一次,我想知道如何从数据库更新数据。我已经尝试过这段代码,但它给了我一个错误关键字'JOIN'附近的语法不正确。请帮我解决这个问题。 关于数据库的信息 表stringInstrumentItem(列brandId是外键并引用表品牌的主键,也称为brandId): itemId brandId model 1 1 ; xyz 2 1 abc 3 2 hjk 表品牌(其主要名称为brandId,引用的是表格strinInstrumentItem): brandId name image 1 Ibanez xyz.jpg 2 Fender abc.jpg 3 Gibson hjk.jpg b $ b 主要目标是通过gridview更新表品牌名称列。例如在brandId#1中,名字等于Ibanez,我想将其改为Jackson。它应该能够在没有异常错误的情况下工作。如何查询这个? 我的尝试:

take note I'm still a beginner in databases but willing to learn. This time, I want to know how to update a data from database. I've tried this code but it is giving me an error "Incorrect syntax near the keyword 'JOIN'". Kindly help me on solving this one. Info about the database Table stringInstrumentItem(The column brandId is the foreign key and references the primary key of table brand, which is also named brandId): itemId brandId model 1 1 xyz 2 1 abc 3 2 hjk Table brand(which has the primary key called brandId that is referencing by the table strinInstrumentItem): brandId name image 1 Ibanez xyz.jpg 2 Fender abc.jpg 3 Gibson hjk.jpg Main goal is to update the column called name in table brand through my gridview. Like for example in brandId#1, name is equals to Ibanez, and I want to change it to Jackson. It should be able to work without the exception error. How to query this one? What I have tried:

string queryGuitarItems = "UPDATE stringInstrumentItem JOIN brand ON stringInstrumentItem.brandId = brand.brandId SET stringInstrumentItem.brandId = @brandId IN (SELECT brand.brandId FROM brand WHERE name = @oldBrandName"; using (SqlConnection connectionGuitarItems = new SqlConnection(ConfigurationManager.ConnectionStrings["musicStoreConnection"].ToString())) { using (SqlCommand commandGuitarItems = new SqlCommand(queryGuitarItems, connectionGuitarItems)) { List<SqlParameter> parameterGuitarItems = new List<SqlParameter>(); parameterGuitarItems.Add(new SqlParameter("@brandId", newName.Text)); parameterGuitarItems.Add(new SqlParameter("@oldBrandName", oldName)); connectionGuitarItems.Open(); GetParameterGuitarItems(commandGuitarItems,parameterGuitarItems.ToArray()); commandGuitarItems.ExecuteNonQuery(); connectionGuitarItems.Close(); commandGuitarItems.Parameters.Clear(); } }

推荐答案

查看帖子中的查询,看来你正在尝试更新brandid在品牌StringInstrumentItem表中为oldBrandName。查询应该是这样的.. UPDATE SII SET SII.brandId = b.brandId FROM stringInstrumentItem SII 内连接品牌b ON SII.brandId = b.brandId AND b.name = @oldBrandName looking at the query in your post, it seems you are trying to update brandid in brand StringInstrumentItem table for the oldBrandName. the query should be like this.. UPDATE SII SET SII.brandId = b.brandId FROM stringInstrumentItem SII inner join brand b ON SII.brandId = b.brandId AND b.name = @oldBrandName

我认为您的查询需要看起来像这: I think your query needs to look something like this: UPDATE SII SET SII.brandId = @brandId FROM stringInstrumentItem SII JOIN brand ON SII.brandId = brand.brandId WHERE brand.name = @oldBrandName

但这没有任何意义,因为你已经加入同一brandId,所以也许这就是你所需要的:

But that would make no sense, as you already JOIN on the same brandId, so maybe this is what you need:

UPDATE SII SET SII.brandId = @brandId FROM stringInstrumentItem SII, brand WHERE brand.name = @oldBrandName

更多推荐

使用ASP.NET关键字'join'附近的语法不正确

本文发布于:2023-11-12 09:38:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581138.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不正确   语法   关键字   ASP   NET

发布评论

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

>www.elefans.com

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