这是我的代码
Imports System.Data.SqlClient
Public Class pinchange
Private Sub btn_enter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_enter.Click
Using _conn As New SqlConnection("Data Source=HOME-PC; Initial Catalog=csbanking; Integrated Security= true")
Using _comm As New SqlCommand()
With _comm
.Connection = _conn
.CommandText = "UPDATE USERLOGIN SET USER_PIN = @pin WHERE USER_LOGIN = @id"
.CommandType = CommandType.Text
.Parameters.AddWithValue("@pin", txt_newpin.Text)
.Parameters.AddWithValue("@id", Login.txt_id.Text)
End With
Try
_conn.Open()
_comm.ExecuteNonQuery()
Catch ex As SqlException
MsgBox(ex.Message.ToString())
End Try
End Using
End Using
MessageBox.Show("Pin Change Successful")
_1stpage.Show()
Login.txt_id.Text = ""
Security.msktxt_pin.Text = ""
Me.Hide()
End Sub
End Class
代码成功但在我添加&#34后无法更新Pin更改;其中USER_LOGIN = @ id" 怎么了?
答案 0 :(得分:0)
试一下
Using _conn As New SqlConnection("Data Source=HOME-PC; Initial Catalog=csbanking; Integrated Security= true")
Using _comm As New SqlCommand()
With _comm
.Connection = _conn
.CommandText = "UPDATE USERLOGIN SET USER_PIN = @pin WHERE USER_LOGIN = @id"
.CommandType = CommandType.Text
.Parameters.Add("@pin", SqlDbType.NVarChar).Value = txt_newpin.Text
.Parameters.Add("@id", SqlDbType.NVarChar).Value = txt_id.Text
End With
Try
_conn.Open()
_comm.ExecuteNonQuery()
Catch ex As SqlException
MsgBox(ex.Message.ToString())
End Try
End Using
End Using
MessageBox.Show("Pin Change Successful")
_1stpage.Show()
Login.txt_id.Text = ""
Security.msktxt_pin.Text = ""
Me.Hide()
答案 1 :(得分:0)
我已经解决了我的问题
在我的登录表格中 public shared id as string =“” 然后 id = txt_id.text
在我的更改表格中 以前 .CommandText =“UPDATE USERLOGIN SET USER_PIN = @pin WHERE USER_LOGIN = @id” 然后 .Parameters.AddWithValue(“@ id”,Login.txt_id.Text)
解决 .CommandText =“UPDATE USERLOGIN SET USER_PIN = @pin WHERE USER_LOGIN = @id” 然后 .Parameters.AddWithValue(“@ id”,Login.id)
感谢每个人都不关心并帮助我解决问题 感谢您对UR KINDNESS的帮助和感谢,并且非常有帮助答案 2 :(得分:-1)
到目前为止,一切似乎都很好。
如果您可以展示您的表架构,那就太棒了。
可能传递参数可能有拼写问题或其他什么。
另外,尝试使用存储过程方法。
Create procedure dbo.[Usp_UserPin_Update]
@UserPin varchar(20) ,
@UserID int
AS
BEGIN
UPDATE dbo.[UserLogin]
SET User_Pin = @UserPin
WHERE User_Id = @UserID
END
它应该可以正常工作。
希望有所帮助!