Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在提交时运行sql代码?_Javascript_Sql_Asp.net_Oledb - Fatal编程技术网

Javascript 如何在提交时运行sql代码?

Javascript 如何在提交时运行sql代码?,javascript,sql,asp.net,oledb,Javascript,Sql,Asp.net,Oledb,我想知道如何在提交时运行SQL代码 我想跑 o_con.Open(); System.Data.OleDb.OleDbDataAdapter da2 = new System.Data.OleDb.OleDbDataAdapter(o_command2); System.Data.DataSet ds2 = new System.Data.DataSet(); da2.Fill(ds2, "RegisterDatabase"); if (ds2.Tables["RegisterDatabase

我想知道如何在提交时运行SQL代码 我想跑

o_con.Open();
System.Data.OleDb.OleDbDataAdapter da2 = new 
System.Data.OleDb.OleDbDataAdapter(o_command2);
System.Data.DataSet ds2 = new System.Data.DataSet();
da2.Fill(ds2, "RegisterDatabase");
if (ds2.Tables["RegisterDatabase"].Rows.Count > 0)
     {
         Response.Write("User exists!!!");
     }
o_con.Close();
当按下提交按钮时。 此外,我还有一个JavaScript函数,用于检查输入是否有效,对于用户名,我只检查它是否为空

function checkStuff() {
    var counter = 0;
    if (document.getElementById("username").value == "") {
        document.getElementById("error1").style.visibility = "visible";
    } else {
        document.getElementById("error1").style.visibility = "hidden";
        counter++;
    }
如果用户名存在,而不是Respond.Write,error1的innerHTML更改为“User ready exists”,并且计数器不增加1,我可以这样做吗?可能在checkStuff函数中包含sql代码?(如果可能的话)


编辑:刚意识到我忘了提。SQL代码位于另一个页面中,因为Request.Form,我希望它与注册表单位于同一页面上,因此它不会重新启动页面(因为这样我就必须响应。重定向到注册页面),但是我不知道您是否可以从同一页面请求输入值。

提交将自动将您的表单发布到该页面。 您需要的是AJAX。只需添加到您的按钮

OnClientClick="CheckUserName(); return false"
然后需要一个javascript函数

function CheckUserName()
{
  //call function using AJAX
}
互联网上有一些很好的例子。其中之一就是使用webmethods。您还可以使用updatepanel或CallbackEventHandler

下面是一个使用Webmethods的示例