【发布时间】:2023-03-03 01:42:01
【问题描述】:
我有下面的代码,它确实有效,但我需要向它添加更多功能。我要添加的功能是我在下面的代码中注释的文本。
Dim objSQLConnection As SqlConnection
Dim objSQLCommand As SqlCommand
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim intID As Integer = CType(Request.Form("ID"), Integer)
Dim strHeading As String = CType(Request.Form("Heading"), String)
Dim intState As Integer = CType(Request.Form("State"), Integer)
Dim strUser As String = CType(Request.Form("User"), String)
objSQLConnection = New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("connString"))
''#count if records with this user already exist in the database below
If intState = 1 Then
objSQLCommand = New SqlCommand("insert into table1 (id, heading, user) values (@intID, @strHeading, @strUser)", objSQLConnection)
objSQLCommand.Parameters.Add("@intID", SqlDbType.Int, 4).Value = intID
objSQLCommand.Parameters.Add("@strHeading", SqlDbType.VarChar, 255).Value = strHeading
objSQLCommand.Parameters.Add("@strUser", SqlDbType.VarChar, 3).Value = strUser
ElseIf intState = 0 Then
objSQLCommand = New SqlCommand("delete from table1 where id = @intID and user = @strUser", objSQLConnection)
objSQLCommand.Parameters.Add("@intID", SqlDbType.Int, 4).Value = intID
objSQLCommand.Parameters.Add("@strUser", SqlDbType.VarChar, 3).Value = strUser
End If
objSQLCommand.Connection.Open()
objSQLCommand.ExecuteNonQuery()
objSQLCommand.Connection.Close()
End
在 if 语句之前,我想查明数据库是否已经在 strUser 变量中包含用户名的记录。这样做的最佳方法是什么?
【问题讨论】:
-
请不要转发相同的问题:stackoverflow.com/questions/4658869/…
-
我想到了不同的问题,问题一,统计用户,问题二,重复记录。
标签: .net asp.net sql vb.net .net-3.5