比较受影响的行数(Compare Number of Rows affected)
我正在尝试比较一个字符串(网络ID)和使用SQL Like命令,返回受影响的行数(如果找到或不找到用户名)但是在我的代码中我总是得到“-1”,我找不到原因,用户名是正确的,并通过在SQL Server管理中运行查询在SQL表中找到。
Try Dim Con As New SqlConnection Con.ConnectionString = "Data Source=WCRDUSMJEMPR9\SQLEXPRESS;Initial Catalog=MicroDB;Integrated Security=True" Con.Open() Dim SQL2 As String SQL2 = "SELECT * from MicroDB_Users WHERE Users LIKE '+@Usercheck+'" Dim cmd2 As New SqlCommand(SQL2, Con) cmd2.Parameters.AddWithValue("@Usercheck", TextBox1.Text) Dim obj2 = cmd2.ExecuteNonQuery Con.Close() If obj2 > 0 Then MsgBox(obj2) Response.Redirect("~\ControlCharts\AddData_Control.aspx") Label7_Control.Visible = False Else MsgBox(obj2) Label7_Control.Text = ("You are not authorized to Add Data") Label7_Control.Visible = True End If Catch ex As Exception MsgBox(Err.Description)
如您所见,我使用IF来比较用户是否被发现(1行受影响)或未找到(受影响的0行)。
I'm trying to compare a string (network ID) and using a SQL Like command, return the numbers of rows affected (if the user name was found or not) however in my code I'm always getting " -1 " which i can not find why, the username is correct and found in the SQL table by running a query in SQL Server Mgt.
Try Dim Con As New SqlConnection Con.ConnectionString = "Data Source=WCRDUSMJEMPR9\SQLEXPRESS;Initial Catalog=MicroDB;Integrated Security=True" Con.Open() Dim SQL2 As String SQL2 = "SELECT * from MicroDB_Users WHERE Users LIKE '+@Usercheck+'" Dim cmd2 As New SqlCommand(SQL2, Con) cmd2.Parameters.AddWithValue("@Usercheck", TextBox1.Text) Dim obj2 = cmd2.ExecuteNonQuery Con.Close() If obj2 > 0 Then MsgBox(obj2) Response.Redirect("~\ControlCharts\AddData_Control.aspx") Label7_Control.Visible = False Else MsgBox(obj2) Label7_Control.Text = ("You are not authorized to Add Data") Label7_Control.Visible = True End If Catch ex As Exception MsgBox(Err.Description)
As you can see, i;m using a IF to compare if the user was found ( 1 row affected) or if it was not found ( 0 rows affected).
原文:https://stackoverflow.com/questions/14469564
最满意答案
在查看您在评论中提供的网站后,我注意到您的提交表单处理程序仅提交了4个字段(
name
,phone
和comments
)。 这需要修改为包括g-recaptcha-response
。来自第1141行的http://zacktarrcreations.com/AFK/js/plugins.js :
$('#contactform').submit(function(){ var action = $(this).attr('action'); $("#message").slideUp(500,function() { $('#message').hide(); $.post(action, { name: $('#name').val(), email: $('#email').val(), phone: $('#phone').val(), comments: $('#comments').val(), }, function(data){ document.getElementById('message').innerHTML = data; $('#message').slideDown('slow'); $('#submit').removeAttr('disabled'); if(data.match('success') != null) $('#contactform').slideUp('slow'); } ); }); return false; });
改成:
$('#contactform').submit(function(){ var action = $(this).attr('action'); $("#message").slideUp(500,function() { $('#message').hide(); $.post(action, { name: $('#name').val(), email: $('#email').val(), phone: $('#phone').val(), comments: $('#comments').val(), "g-recaptcha-response": $('#g-recaptcha-response').val(), }, function(data){ document.getElementById('message').innerHTML = data; $('#message').slideDown('slow'); $('#submit').removeAttr('disabled'); if(data.match('success') != null) $('#contactform').slideUp('slow'); } ); }); return false; });
经过测试,它对我有用。
After looking at your website that you provided in the comments, I noticed your submit form handler is only submitting 4 fields (
name
,phone
, andcomments
). This needs to be modified to includeg-recaptcha-response
.From http://zacktarrcreations.com/AFK/js/plugins.js on line 1141:
$('#contactform').submit(function(){ var action = $(this).attr('action'); $("#message").slideUp(500,function() { $('#message').hide(); $.post(action, { name: $('#name').val(), email: $('#email').val(), phone: $('#phone').val(), comments: $('#comments').val(), }, function(data){ document.getElementById('message').innerHTML = data; $('#message').slideDown('slow'); $('#submit').removeAttr('disabled'); if(data.match('success') != null) $('#contactform').slideUp('slow'); } ); }); return false; });
Change to:
$('#contactform').submit(function(){ var action = $(this).attr('action'); $("#message").slideUp(500,function() { $('#message').hide(); $.post(action, { name: $('#name').val(), email: $('#email').val(), phone: $('#phone').val(), comments: $('#comments').val(), "g-recaptcha-response": $('#g-recaptcha-response').val(), }, function(data){ document.getElementById('message').innerHTML = data; $('#message').slideDown('slow'); $('#submit').removeAttr('disabled'); if(data.match('success') != null) $('#contactform').slideUp('slow'); } ); }); return false; });
Tested and it worked for me.
相关问答
更多-
我想你是在localhost中使用这段代码。 如果是这样,那么api将不起作用。 api用api密钥检查url。 因此,如果您使用某个网址注册并尝试在其他网站上进行测试,那么api将无效。 您可以在教程http://blog.jambura.com/2013/01/02/use-recaptcha-in-cakephp-app/?fb_comment_id=fbc_576497325700235_7768923_699586046724695#f2d979a62c中查看此评论。 I resorted to ...
-
感谢您的支持人员。 如果有人在将来遇到这个问题,我发现这个问题决定发布。 我的表单就像我的桌子一样
显然,表格应该先是表格! Thanks for your support guys. I found the issue so decided to post if anyone comes across this problem in the future. My form was inside my table, like
< ...
Recaptcha不渲染(Recaptcha not rendering)[2023-04-18]
reCAPTCHA页面本身表示将script标记放在head标记内,因此它应该在其他所有内容之前加载。 另外,检查你是否有两个script标签...... 眨眼 The reCAPTCHA page itself says to put the script tag inside the head tag, so it should load before everything else. Also, check if you have two script tags...wink解 我对我的解决方案不满意,但它是迄今为止唯一有效的解决方案。 HTML