本文介绍了使数据插入数据库而不是returni的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是网络方法:

this is the web method:

[WebMethod]
      public string Register(string Email, string Name, string Surname, string Password, string SecurityQuestion, string SecurityAnswer)
      {
          string result = "Invalid";
          try
          {
              conn = new OleDbConnection(connString);
              conn.Open();
              OleDbCommand cmd = conn.CreateCommand();
              cmd.CommandText = "SELECT * FROM [RegisteredUsers] WHERE Email = '" + Email + "'";

              OleDbDataReader dbreader = cmd.ExecuteReader();

              if (dbreader.HasRows)
              {
                  result = "exists";
              }
              else
              {
                  cmd = conn.CreateCommand();
                  cmd.CommandText = "INSERT INTO [RegisteredUsers] WHERE (Email, Name, Surname,Password,SecurityQuestion,SecurityAnswer) VALUES ('" + Email + "', '" + Name+ "', '" + Surname + "',  '" + Password + "','"+ SecurityQuestion +"','"+ SecurityAnswer +"')";
                  int a = cmd.ExecuteNonQuery();

                  if (a > 0)
                  {
                      result = "valid";
                  }
              }
          }
          catch (Exception)
          {
              result = "error";
          }

          return result;
      }
  }



点击按钮


the button click

protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            string result = s.Register(txtEmail.Text, txtName.Text, txtSurname.Text, txtPassword.Text, drpQuestions.Text, txtAnswer.Text);
            if (result == "True")
            {
                lblError2.Text = ("Successfully registered");

            }
            else
            {
                lblError2.Text = ("Unsuccessful");
            }
        }

推荐答案

catch (Exception ex)
    {
    result = "error";
    Debug.WriteLine(ex.Message);
    }

然后在Debug.WriteLine行上放置一个断点,看看调试器点击它时会得到什么。

Then put a breakpoint on the Debug.WriteLine line and see what you get when the debugger hits it.


这篇关于使数据插入数据库而不是returni的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 07:31
查看更多