【发布时间】:2011-06-09 03:16:20
【问题描述】:
由于某种原因,下面的 if 语句不起作用
''# count if records with this user already exist in the database below
objSQLCommand = New SqlCommand("select count(id) as record_count from table1 where user = @strUser", objSQLConnection)
objSQLCommand.Parameters.Add("@strUser", SqlDbType.VarChar, 3).Value = strUser
objSQLCommand.Connection.Open()
intRecordCount = CType(objSQLCommand.ExecuteScalar(), Integer)
objSQLCommand.Connection.Close()
''# duplicate default rows in database if username not in database
If intRecordCount = 0 Then
Response.Write(intRecordCount)
objSQLCommand = New SqlCommand("insert into table1 (heading, user) select heading, @strUser as user from table1 where defaults = @intDefault", objSQLConnection)
objSQLCommand.Parameters.Add("@strUser", SqlDbType.VarChar, 3).Value = strUser
objSQLCommand.Parameters.Add("@intDefault", SqlDbType.Int, 4).Value = 1
End If
Response.Write(intRecordCount) 如果找到 0 条记录,则返回 0;如果我在数据库中手动为用户插入 2 行,则返回 2。
但由于某种原因,if 语句不起作用。如果我手动运行“插入选择”查询,它会完美运行。
我做错了什么?
【问题讨论】:
标签: .net asp.net sql vb.net .net-3.5