0

这是我进行更新的存储过程,当我使用 SQL Server 测试该过程时,它运行良好。

ALTER PROCEDURE [TKSFlex].[UpdateComment]
-- Add the parameters for the stored procedure here
  @Comment char(50),
  @Employee char(25)
AS
BEGIN TRANSACTION 
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT On;

    -- Insert statements for procedure here

 Update whiteboard set Comment = @Comment 
 where Employee = @Employee

COMMIT

这是单击更新按钮时执行的代码

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal es System.EventArgs) Handles btnUpdate.Click

    InputsModule.Employee = "'Mathe BF'"
    Objconn.Open()

    dbcommand.Connection = Objconn

    dbcommand.CommandType = CommandType.StoredProcedure
    dbcommand.CommandText = "[TKSFlex].[UpdateComment]"

    dbcommand.Parameters.AddWithValue("@Comment", txtComment.Text)
    dbcommand.Parameters.AddWithValue("@Employee", InputsModule.Employee)

    'dbcommand.Parameters.Add("@Comment", SqlDbType.Char).Value = txtComment.Text
    'dbcommand.Parameters.Add("@Employee", SqlDbType.Char).Value = InputsModule.Employee
    Dim i As Integer = 0

    Try
        i = dbcommand.ExecuteNonQuery()
    Catch ex As SqlException
        MsgBox("failed")
    End Try

    Objconn.Close()
End Sub

执行查询时表没有更新并且没有抛出异常,这意味着代码确实被执行但没有对数据库进行修改,我只是不确定我哪里出错了

4

2 回答 2

2

最合乎逻辑的原因是:

InputsModule.Employee = "'Mathe BF'"

那应该是:

InputsModule.Employee = "Mathe BF"

ADO.NET 将为您引用该参数。手动输入引号将导致搜索quote-mathe bf-quote,它可能不存在:)

于 2012-12-23T19:59:50.333 回答
0

对于添加值,您需要指定参数的类型,如下面的代码所示。

SqlParameter parameter = command.Parameters.AddWithValue("paramName", value); parameter.SqlDbType = SqlDbType.Int;

于 2012-12-23T19:59:50.663 回答