【发布时间】:2012-12-23 19:49:03
【问题描述】:
这是我进行更新的存储过程,当我使用 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
执行查询时表没有更新并且没有抛出异常,这意味着代码确实被执行但没有对数据库进行修改,我只是不确定我在哪里出错了
【问题讨论】:
-
您需要为任何字符参数定义 长度 - 例如使用这个:
dbcommand.Parameters.Add("@Comment", SqlDbType.Char, 50).Value = txtComment.Text- 否则,您的参数只有一个字符长!
标签: sql-server vb.net visual-studio-2010