System.ArgumentNullException:Value不能为null参数名称:input

时间:2014-10-23 06:23:25

标签: c# asp.net system argumentnullexception

当我运行此文件时,出现以下错误:

  

' /'中的服务器错误应用

     

值不能为空。参数名称:输入描述:An   在执行当前Web期间发生了未处理的异常   请求。请查看堆栈跟踪以获取有关的更多信息   错误以及它在代码中的起源。

     

异常详细信息:System.ArgumentNullException:值不能   空值。参数名称:输入

来源错误:

Line 43:             dr["Assignee"] = result.Assignee;
Line 44:             dr["PatentNumber"] = result.PatentNumber;
Line 45:             dr["Date"] = DateTime.Parse(result.ApplicationDate.ToString()).ToString("dd MMM yyyy");
Line 46:             dt.Rows.Add(dr);
Line 47:         }

源文件:d:\ dzhosts \ localuser \ kareem \ www.kareem2.somee.com \ GooglePatentSearch.aspx.cs第45行

  

堆栈追踪:

     

[ArgumentNullException:Value不能为null。参数名称:输入]
  System.Text.RegularExpressions.Regex.Replace(String input,String   更换)+6402895
  System.Text.RegularExpressions.Regex.Replace(String input,String   模式,字符串替换)+88
  Google.API.Search.SearchUtility.RFC2822DateTimeParse(String str)+50
  Google.API.Search.GpatentResult.Google.API.Search.IPatentResult.get_ApplicationDate()   +12 GooglepatentSearch.Button1_Click(对象发件人,EventArgs e)位于d:\ dzhosts \ localuser \ kareem \ www.kareem2.somee.com \ GooglePatentSearch.aspx.cs:45   System.Web.UI.WebControls.Button.OnClick(EventArgs e)+9615678
  System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串   eventArgument)+103
  System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串   eventArgument)+10
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler   sourceControl,String eventArgument)+13
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)   +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)   1724

如何解决此问题?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Google.API.Search;

public partial class GooglepatentSearch : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dlSearch.DataSource = null;
            dlSearch.DataBind();
            TextBox1.Text = "";
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("Title", typeof(string)));
        dt.Columns.Add(new DataColumn("Url", typeof(string)));
        dt.Columns.Add(new DataColumn("Image", typeof(string)));
        dt.Columns.Add(new DataColumn("Status", typeof(string)));
        dt.Columns.Add(new DataColumn("Content", typeof(string)));
        dt.Columns.Add(new DataColumn("Assignee", typeof(string)));
        dt.Columns.Add(new DataColumn("PatentNumber", typeof(string)));
        dt.Columns.Add(new DataColumn("Date", typeof(string)));
        GpatentSearchClient client = new GpatentSearchClient("www.c-sharpcorner.com");
        IList<IPatentResult> results = client.Search(TextBox1.Text, 30);
        foreach (IPatentResult result in results)
        {
            DataRow dr = dt.NewRow();
            dr["Title"] = result.Title.ToString();
            dr["Url"] = result.Url;
            dr["Image"] = result.TbImage;
            dr["Status"] = result.PatentStatus;
            dr["Content"] = result.Content;
            dr["Assignee"] = result.Assignee;
            dr["PatentNumber"] = result.PatentNumber;
            dr["Date"] = DateTime.Parse(result.ApplicationDate.ToString()).ToString("dd MMM yyyy");
            dt.Rows.Add(dr);
        }
        dlSearch.DataSource = dt;
        dlSearch.DataBind();
    }
}




<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GooglepatentSearch.aspx.cs" Inherits="GooglepatentSearch" Debug="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
  <form id="form2" runat="server">
    <div>
      <asp:TextBox ID="TextBox1" runat="server" Width="300px"></asp:TextBox>
      <asp:Button ID="btnSearch" runat="server" Text="Google Patent Search" OnClick="Button1_Click" />
      <br />
      <asp:DataList ID="dlSearch" runat="server" Width="600px">
        <ItemTemplate>
          <asp:LinkButton ID="LinkButton1" runat="server" Text='<%#Eval("Title")+"("+Eval("Assignee")+")" %>' PostBackUrl='<%#Eval("Url") %>'>
          </asp:LinkButton><br />
          <asp:Label ID="Label1" runat="server" Text='<%#Eval("Content") %>'>
          </asp:Label>
          <br />
          <img alt="image" src='<%#Eval("Image") %>' />
          <br />
          <asp:Label ID="Label2" runat="server" Text='<%# "(Status:-"+Eval("Status")+", Patent Number:-"+Eval("PatentNumber")+",Application Date:-"+Eval("Date") +")"%>'>
          </asp:Label>
          <br />
        </ItemTemplate>
        <FooterTemplate>
          <asp:Label Visible='<%#bool.Parse((dlSearch.Items.Count==0).ToString())%>' runat="server" ID="lblNoRecord" Text="No Record Found!">
          </asp:Label>
        </FooterTemplate>
      </asp:DataList>
    </div>
  </form>
</body>
</html>

此代码的来源: http://www.c-sharpcorner.com/UploadFile/29d7e0/google-patent-search-in-Asp-Net/

0 个答案:

没有答案