Web服务出错,请高手看看,哪里不对?
拜托拜托
错误信息
“/TQWebService/TQWeb_WebUI”应用程序中的服务器错误。
--------------------------------------------------------------------------------System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.NullReferenceException: 未将对象引用设置到对象的实例。 at DataAccess.PersonnelClass.UpdatePersonnel(Int32 pid, String pname, String pbusiness) in c:\inetpub\wwwroot\tqwebservice\tqwebservice\tqweb\dataaccess\personnelclass.cs:line 48 at WebService.TQWebService.UpDatePersonnel(Int32 pid, String pname, String pbusinness) in C:\Inetpub\wwwroot\TQWebService\TQWeb_WebService\TQWebService.asmx.cs:line 77 --- 内部异常堆栈跟踪的结尾 --- 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.NullReferenceException: 未将对象引用设置到对象的实例。 at DataAccess.PersonnelClass.UpdatePersonnel(Int32 pid, String pname, String pbusiness) in c:\inetpub\wwwroot\tqwebservice\tqwebservice\tqweb\dataaccess\personnelclass.cs:line 48 at WebService.TQWebService.UpDatePersonnel(Int32 pid, String pname, String pbusinness) in C:\Inetpub\wwwroot\TQWebService\TQWeb_WebService\TQWebService.asmx.cs:line 77 --- 内部异常堆栈跟踪的结尾 ---
数据库CREATE TABLE [dbo].[personnel] (
[personnelid] [int] IDENTITY (1, 1) NOT NULL ,
[personnelname] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[personnelbusiness] [char] (10) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]CREATE PROCEDURE dbo.updatapresonnel (
@personnelid int=NULL,
@personnelname char(10)=NULL ,
@personnelbusiness char(10)=NULL
)AS
SET NOCOUNT ON
UPDATE presonnel SET personnelname=@personnelname,
                             personnelbusiness=@personnelbusiness
WHERE personnelid=@personnelid 

RETURN 
数据访问层
public DataSet UpdatePersonnel(int pid,string pname,string pbusiness)
{
SqlConnection conn = new SqlConnection(dsn); SqlDataAdapter adapter = new SqlDataAdapter(CommandText,conn);
DataSet ds = new DataSet("personnel"); SqlParameter workParm = adapter.UpdateCommand.Parameters.Add("@personnelid", SqlDbType.Int);
workParm.SourceColumn = "personnelid";
workParm.SourceVersion = DataRowVersion.Original; adapter.UpdateCommand.Parameters.Add("@personnelname",SqlDbType.VarChar,10,"personnelname");
adapter.UpdateCommand.Parameters["@personnelname"].Value = pname;
adapter.UpdateCommand.Parameters.Add("@personnelbusiness",SqlDbType.VarChar,10,"personnelbusiness");
adapter.UpdateCommand.Parameters["@personnelbusiness"].Value = pbusiness;
adapter.Fill(ds);
return ds;
}web服务 [WebMethod]
public DataSet UpDatePersonnel(int pid,string pname,string pbusiness)
{
PersonnelClass pclass = new PersonnelClass();
return pclass.UpdatePersonnel(pid,pname,pbusiness);
}WebForm界面:webform1.aspx.cs:
private void DataGrid1_UpdateCommand_1(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int id=1;
string pid;
string pname;
string pbusiness; pid = e.Item.Cells[1].Text;

pname = e.Item.Cells[2].Text;
pbusiness = e.Item.Cells[3].Text; WebService1.TQWebService service = new WebUI.WebService1.TQWebService();
DataSet ds = service.UpDatePersonnel(id,pname,pbusiness);

this.DataGrid1.EditItemIndex = -1;
BindGrid();
}webform1.aspx
在一个DataGrid中:
<Columns>
<asp:BoundColumn Visible="False" DataField="personnelid" HeaderText="标号" DataFormatString="{0:d}"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="人员姓名">
<HeaderStyle Wrap="False" Width="100px"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:Label id=Labelpersonnelname runat="server" Width="96px" Text='<%# DataBinder.Eval(Container, "DataItem.personnelname") %>'>
</asp:Label>
</ItemTemplate>
<FooterStyle Wrap="False"></FooterStyle>
<EditItemTemplate>
<asp:TextBox id=txtNationalityItem runat="server" BorderStyle="Groove" Width="96px" Text='<%# DataBinder.Eval(Container, "DataItem.personnelname") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="职名">
<HeaderStyle Wrap="False" Width="100px"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:Label id="Label1" runat="server" Width="96px" Text='<%# DataBinder.Eval(Container, "DataItem.personnelbusiness") %>'>
</asp:Label>
</ItemTemplate>
<FooterStyle Wrap="False"></FooterStyle>
<EditItemTemplate>
<asp:TextBox id="TextBox1" runat="server" Width="96px" Text='<%# DataBinder.Eval(Container, "DataItem.personnelbusiness") %>' BorderStyle="Groove">
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn Text="选择" CommandName="Select">
<ItemStyle Wrap="False"></ItemStyle>
</asp:ButtonColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="更新" CancelText="取消" EditText="编辑">
<ItemStyle Wrap="False"></ItemStyle>
</asp:EditCommandColumn>
<asp:ButtonColumn Text="删除" CommandName="Delete">
<ItemStyle Wrap="False"></ItemStyle>
</asp:ButtonColumn>
</Columns>

解决方案 »

  1.   

    workParm.SourceVersion = DataRowVersion.Original;
    你从哪里能拿的到Original的值?
      

  2.   

    [SoapException: System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.NullReferenceException: 未将对象引用设置到对象的实例。
       at DataAccess.PersonnelClass.UpdatePersonnel(Int32 pid, String pname, String pbusiness) in c:\inetpub\wwwroot\tqwebservice\tqwebservice\tqweb\dataaccess\personnelclass.cs:line 48
       at WebService.TQWebService.UpDatePersonnel(Int32 pid, String pname, String pbusinness) in c:\inetpub\wwwroot\tqwebservice\tqweb_webservice\tqwebservice.asmx.cs:line 77
       --- 内部异常堆栈跟踪的结尾 ---]personnelclass.cs:line 48:  数据访问层SqlParameter workParm = adapter.UpdateCommand.Parameters.Add("@personnelid", SqlDbType.Int);tqwebservice.asmx.cs:line 77:Web服务层
    return pclass.UpdatePersonnel(pid,pname,pbusinness);