這是我的存儲過程,它執行更新,當我使用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' - 否則,你的參數是**只有一個字符長**! –