{“'('。附近的语法不正确。”}

时间:2018-10-01 10:51:02

标签: c# sql asp.net sql-server

嗨,我正在尝试使用以下代码更新SQL Server中的表,但出现错误:

  

{“'('。附近的语法不正确。”}

有人可以告诉我我要去哪里了吗,任何帮助将不胜感激

 protected void btnUpdate_Click(object sender, EventArgs e)
    {
        try
        {
            string pNameTemp = DropDownList1.SelectedValue;
            string sNameTemp = txtEditSkill.Text;
            myConnection.Open();
            SqlCommand com = new SqlCommand("UPDATE [dbo].[test1] SET (sName) = (@sName) WHERE fName LIKE @field", myConnection);
            com.Parameters.AddWithValue("@field", pNameTemp);
            com.Parameters.AddWithValue("@sName", sNameTemp);
            com.ExecuteNonQuery();
            //txtEditSkill.Text = com.ExecuteScalar().ToString();
            myConnection.Close();
        }

        catch (Exception ex)
        {
            throw new Exception(ex.Message);
        }
    }

3 个答案:

答案 0 :(得分:6)

var strings = grdLookupPracticeMultiple.GridView.GetSelectedFieldValues("ID")
                      .ConvertAll(s => (string)s);

SQL Server的 <Style TargetType="{x:Type dragablz:TabablzControl}" x:Key="TabablzControlStyle"> <Setter Property="NewItemFactory" Value="{x:Static stUi:UINewItem.Factory}" /> <Setter Property="ItemsSource" Value="{Binding Items}" /> <Setter Property="ClosingItemCallback" Value="{Binding ClosingTabItemHandler}" /> <Setter Property="ShowDefaultCloseButton" Value="False" /> <Setter Property="AdjacentHeaderItemOffset" Value="-10" /> <Setter Property="ItemContainerStyle" Value="{StaticResource TrapezoidDragableTabItemStyle}" /> <Setter Property="HeaderMemberPath" Value="Header" /> <Setter Property="Background" Value="Red"/> <Setter Property="InterTabController" Value="{StaticResource InterTabController}" /> <Setter Property="Margin" Value="0 8 0 0" /> </Style> <Style TargetType="{x:Type dragablz:TabablzControl}" x:Key="ModernControlStyle"> <Setter Property="NewItemFactory" Value="{x:Static stUi:UINewItem.Factory}" /> <Setter Property="ItemsSource" Value="{Binding Items}" /> <Setter Property="ClosingItemCallback" Value="{Binding ClosingTabItemHandler}" /> <Setter Property="ShowDefaultCloseButton" Value="False" /> <Setter Property="AdjacentHeaderItemOffset" Value="0" /> <Setter Property="HeaderMemberPath" Value="Header" /> <Setter Property="InterTabController" Value="{StaticResource InterTabController}" /> <Setter Property="Margin" Value="0 8 0 0" /> </Style> 语句的语法(请参见docs)在set子句左侧的列名周围没有括号。

答案 1 :(得分:1)

从列名和值周围删除方括号。

SET sName = @sName

您将其与Insert语句混淆,该语句使用用于列和值的方括号语法。

区别在于,在更新中,您将提供以逗号分隔的列和值列表,例如column1 = value1, column2 = value2,在插入过程中,您首先提供列列表,然后提供值列表,例如{{1 }}

答案 2 :(得分:0)

正如其他人所述,只需替换:

UPDATE [dbo].[test1] SET (sName) = (@sName) WHERE fName LIKE @field

UPDATE [dbo].[test1] SET sName = @sName WHERE fName LIKE @field