sql server存储过程来更新记录

vbN*_*bie 2 sql sql-server-2005

我试图创建一个存储过程,从我的程序中获取值并将其插入表中的特定列.我一直在存储过程中收到错误的语法错误,但无法找出原因?程序代码:

            commandObj.CommandText = "sp_insert_profileDetails"

            commandObj.Parameters.Clear()

            Dim m_param As SqlParameter

            m_param = commandObj.Parameters.Add("@authorId", SqlDbType.NVarChar, 100)
            m_param.Direction = ParameterDirection.Input
            m_param.Value = foundProfiles.Item(i)


            m_param = commandObj.Parameters.Add("@age", SqlDbType.NVarChar, 50)
            m_param.Direction = ParameterDirection.Input
            m_param.Value = faceProfileAge.Item(i)

            m_param = commandObj.Parameters.Add("@gender", SqlDbType.NVarChar, 50)
            m_param.Direction = ParameterDirection.Input
            m_param.Value = faceProfileSex.Item(i)

            m_param = commandObj.Parameters.Add("@locale", SqlDbType.NVarChar, 50)
            m_param.Direction = ParameterDirection.Input
            m_param.Value = faceProfileLocation.Item(i)

            m_param = commandObj.Parameters.Add("@pic", SqlDbType.NVarChar, 100)
            m_param.Direction = ParameterDirection.Input
            m_param.Value = faceProfilePic.Item(i)

            Dim recordsAffected As Integer = commandObj.ExecuteNonQuery
            Return recordsAffected



ALTER procedure [dbo].[sp_insert_profileDetails]
@authorId nvarchar(100),
@age nvarchar(50),
@gender nvarchar(50),
@locale nvarchar(50),
@pic nvarchar(100)

AS 
  Begin
  set nocount on
  update [dbo].ProfileFeed
  set [age] = @age,
      [sex] = @gender,
      [locale] = @locale,
      [pic] = @pic
  where 
      [authorId] = @authorId
  end
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏

Dav*_*vid 5

我确实错过了几行代码,但....

您是否指定commandObj.CommandType是System.Data.CommandType.StoredProcedure?

如果您忘记设置此项,.NET默认会将其视为System.Data.CommandType.Text,并且数据库将抛出错误的语法错误.