分析器错误未显示在www.example.com中asp.net

relj7zay  于 2022-11-19  发布在  .NET
关注(0)|答案(2)|浏览(140)

最近,我在www.example.com的asp.netC#框架上工作,我遇到了一个插入查询的问题,但是我看不到解析器的错误,它显示了一个空白页面。这就是为什么我不能找出我的代码的问题。这是我的代码和我的web.config文件。
web.config文件:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>

  <system.web>

      <compilation  targetFramework="4.7.2" />
      <!-- ******************** -->
      
  </system.web>

  <system.codedom>
    <compilers>
      <compiler extension=".cs" language="c#;cs;csharp" warningLevel="4" compilerOptions="/langversion:7.3 /nowarn:1659;1699;1701;612;618" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      <compiler extension=".vb" language="vb;vbs;visualbasic;vbscript" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008,40000,40008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </compilers>
  </system.codedom>
</configuration>

插入查询代码:

sql = "INSERT INTO [transaction] (employeeName, receivedDate, recipient, senderParty, receivedParty, tranNum, email, status, userID)" +
             "values (@employName, @recDate, @recipientName, @sendName, @recName, @tranNumber, @employEmail, @stat, @id)";
            //Response.Write(reciveDate.Value);
            //Response.Write(empEmail);

            using (SqlCommand cmd = new SqlCommand(sql, conn))
            {
                if (conn.State == ConnectionState.Closed)
                conn.Open();
                cmd.Parameters.AddWithValue("@employName", employeeName);
                cmd.Parameters.AddWithValue("@recDate", reciveDate.Value);
                cmd.Parameters.AddWithValue("@recipientName", reciever.Value); ;
                cmd.Parameters.AddWithValue("@sendName", senderAdress.Value);
                cmd.Parameters.AddWithValue("@recName", recieverAdress.Value);
                cmd.Parameters.AddWithValue("@tranNumber", Convert.ToInt32(tranID.Value));
                cmd.Parameters.AddWithValue("@employEmail", empEmail);
                cmd.Parameters.AddWithValue("@stat", "p");
                cmd.Parameters.AddWithValue("@id", empID);
                a = cmd.ExecuteNonQuery();
            }

我尝试将数据插入Microsoft SQL Management服务器,但没有效果,而且我看不到剖析器错误。
如何显示解析器错误?
请帮帮我,谢谢

fivyi3re

fivyi3re1#

您需要放置trycatch并查看异常。
您还需要首先直接在SQLServer中运行查询并查看查询是否有任何错误。
并且我不确定,但是您的查询在这里是不正确的。它正在产生下面的查询。

INSERT INTO [transaction] (employeeName, receivedDate, recipient, senderParty, receivedParty, tranNum, email, status, userID)values (@employName, @recDate, @recipientName, @sendName, @recName, @tranNumber, @employEmail, @stat, @id)

如果你仔细看,值前没有空格。2所以你需要更正它。
请使用using语句声明con。

7lrncoxx

7lrncoxx2#

如前所述,在“值”之前应该有一个空格。
或者使用@作为字符串,并使用换行符。
并且您应该STRONG输入参数。
(don(不使用addwith)
因此:

sql = @"INSERT INTO [transaction] 
(employeeName, receivedDate, recipient, senderParty, receivedParty, tranNum, email, status, userID)
VALUES (@employName, @recDate, @recipientName, @sendName, @recName, @tranNumber, @employEmail, @stat, @id)";

using (SqlCommand cmd = new SqlCommand(sql))
{
    cmd.Parameters.Add("@employName", SqlDbType.NVarChar).Value = employeeName;
    cmd.Parameters.Add("@recDate", SqlDbType.Date).Value = reciveDate.Value;
    cmd.Parameters.Add("@recipientName", SqlDbType.NVarChar).Value = reciever.Value;
    cmd.Parameters.Add("@sendName", SqlDbType.NVarChar).Value = senderAdress.Value;
    cmd.Parameters.Add("@recName", SqlDbType.NVarChar).Value = recieverAdress.Value;
    cmd.Parameters.Add("@tranNumber", SqlDbType.Int).Value = Convert.ToInt32(tranID.Value);
    cmd.Parameters.Add("@employEmail", SqlDbType.NVarChar).Value = empEmail;
    cmd.Parameters.Add("@stat", SqlDbType.NVarChar).Value = "p";
    cmd.Parameters.Add("@id", SqlDbType.Int).Value = empID;
    cmd.ExecuteNonQuery();
}

变量从何而来?
如果是文本框,则使用MyAddress.Text,而不是MyAddress.Value

Edit:显示应用程序中的错误

添加到System.web此内容:

<customErrors mode="Off" >        
</customErrors>

相关问题