未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 35: cmd.Connection=conn;
行 36: cmd.CommandText="Select categoryid,categoryname from categories";
行 37: da.SelectCommand=cmd;
行 38: da.Fill(ds,"customers");//
行 39: drop_categoryid.DataSource=ds.Tables["customers"];
源文件: c:\inetpub\wwwroot\web8\webform5.aspx.cs 行: 37 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
Web9.WebForm5.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\web8\webform5.aspx.cs:37
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
public void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
SqlConnection conn=new SqlConnection("server=localhost;User Id=sa; Password=vcdvcd;DataBase=Northwind");
conn.Open();
SqlCommand cmd=new SqlCommand();
cmd.Connection=conn;
cmd.CommandText="Select categoryid,categoryname from categories where categoryid='"+drop_categoryid.SelectedItem.Value +"'";
da.SelectCommand=cmd;
da.Fill(ds,"customers");//
drop_categoryid.DataSource=ds.Tables["customers"];
drop_categoryid.DataTextField="CategoryName";
drop_categoryid.DataValueField="CategoryID";
drop_categoryid.DataBind(); } }
<%@ Page language="c#" Codebehind="WebForm5.aspx.cs" AutoEventWireup="false" Inherits="Web9.WebForm5" smartNavigation="true"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm5</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">请选择产品类型</FONT>
<asp:dropdownlist id="drop_categoryid" Runat="server" DataTextField="categoryname" DataValueField="categoryid"></asp:dropdownlist><asp:button id="cmd_qry" onclick="data_qry_Click" Runat="server" Text="查询"></asp:button>
<asp:datalist id="DataList1" Runat="server" OnItemCommand="data_disp" BorderColor="#E7E7FF" BorderStyle="None"
BackColor="White" CellPadding="3" GridLines="Horizontal" BorderWidth="1px">
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
<SelectedItemTemplate>
<table id="table1" align="center" cellpadding="1" cellspacing="1">
<tr>
<td>产品编号
<asp:Label ID="lbl_pid" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Productid")%>'>
</asp:Label></td>
</tr>
<tr>
<td>产品名称
<asp:Label ID="lbl_produname" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ProductName")%>'>
</asp:Label></td>
</tr>
<tr>
<td>单价
<asp:Label ID="label3" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"UnitPrice")%>'>
</asp:Label></td>
</tr>
<tr>
<td>库存量
<asp:Label ID="label4" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"UnitsInStock")%>'>
</asp:Label></td>
</tr>
<tr>
<td>
<asp:Button ID="cmd_nav" Runat="server" Text="简易资料" CommandName="Simpledata"></asp:Button>
<asp:Button ID="cmd_modify" Runat="server" Text="编辑" CommandName="editdata"></asp:Button></td>
</tr>
</table>
<asp:Panel ID="Panel1" Runat="server"></asp:Panel>
<asp:Image ID="Image1" Runat="server"></asp:Image>
</SelectedItemTemplate>
<FooterTemplate>
</FooterTemplate>
<ItemTemplate>
<table align="center" border="0" cellspacing="1" cellpadding="1" id="table2">
<tr>
<td>产品编号
<asp:Label ID="lbl_productid" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Productid")%>'>
</asp:Label></td>
</tr>
<tr>
<td>产品名称
<asp:Label ID="lbl_productname" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ProductName")%>'>
</asp:Label></td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" Runat="server" Text="详细资料" CommandName="allData"></asp:Button></td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table>
<tr>
<td>产品编号
<asp:Label ID="Label5" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Productid")%>'>
</asp:Label></td>
</tr>
<tr>
<td>产品名称
<asp:Label ID="Label6" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ProductName")%>'>
</asp:Label></td>
</tr>
<tr>
<td>单价
<asp:TextBox ID="txt_unitprice" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"UnitPrice")%>'>
</asp:TextBox></td>
</tr>
<tr>
<td>库存量
<asp:TextBox ID="txt_stock" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"UnitsInStock")%>'>
</asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Button ID="cmd_save" Runat="server" Text="保存" CommandName="savedata"></asp:Button>
<asp:Button ID="cmd_cancel" Runat="server" Text="取消" CommandName="canceldata"></asp:Button></td>
</tr>
</table>
</EditItemTemplate>
</asp:datalist></form>
</body>
</HTML>
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 35: cmd.Connection=conn;
行 36: cmd.CommandText="Select categoryid,categoryname from categories";
行 37: da.SelectCommand=cmd;
行 38: da.Fill(ds,"customers");//
行 39: drop_categoryid.DataSource=ds.Tables["customers"];
源文件: c:\inetpub\wwwroot\web8\webform5.aspx.cs 行: 37 堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
Web9.WebForm5.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\web8\webform5.aspx.cs:37
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
public void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
SqlConnection conn=new SqlConnection("server=localhost;User Id=sa; Password=vcdvcd;DataBase=Northwind");
conn.Open();
SqlCommand cmd=new SqlCommand();
cmd.Connection=conn;
cmd.CommandText="Select categoryid,categoryname from categories where categoryid='"+drop_categoryid.SelectedItem.Value +"'";
da.SelectCommand=cmd;
da.Fill(ds,"customers");//
drop_categoryid.DataSource=ds.Tables["customers"];
drop_categoryid.DataTextField="CategoryName";
drop_categoryid.DataValueField="CategoryID";
drop_categoryid.DataBind(); } }
<%@ Page language="c#" Codebehind="WebForm5.aspx.cs" AutoEventWireup="false" Inherits="Web9.WebForm5" smartNavigation="true"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm5</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">请选择产品类型</FONT>
<asp:dropdownlist id="drop_categoryid" Runat="server" DataTextField="categoryname" DataValueField="categoryid"></asp:dropdownlist><asp:button id="cmd_qry" onclick="data_qry_Click" Runat="server" Text="查询"></asp:button>
<asp:datalist id="DataList1" Runat="server" OnItemCommand="data_disp" BorderColor="#E7E7FF" BorderStyle="None"
BackColor="White" CellPadding="3" GridLines="Horizontal" BorderWidth="1px">
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle>
<ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
<FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle>
<SelectedItemTemplate>
<table id="table1" align="center" cellpadding="1" cellspacing="1">
<tr>
<td>产品编号
<asp:Label ID="lbl_pid" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Productid")%>'>
</asp:Label></td>
</tr>
<tr>
<td>产品名称
<asp:Label ID="lbl_produname" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ProductName")%>'>
</asp:Label></td>
</tr>
<tr>
<td>单价
<asp:Label ID="label3" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"UnitPrice")%>'>
</asp:Label></td>
</tr>
<tr>
<td>库存量
<asp:Label ID="label4" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"UnitsInStock")%>'>
</asp:Label></td>
</tr>
<tr>
<td>
<asp:Button ID="cmd_nav" Runat="server" Text="简易资料" CommandName="Simpledata"></asp:Button>
<asp:Button ID="cmd_modify" Runat="server" Text="编辑" CommandName="editdata"></asp:Button></td>
</tr>
</table>
<asp:Panel ID="Panel1" Runat="server"></asp:Panel>
<asp:Image ID="Image1" Runat="server"></asp:Image>
</SelectedItemTemplate>
<FooterTemplate>
</FooterTemplate>
<ItemTemplate>
<table align="center" border="0" cellspacing="1" cellpadding="1" id="table2">
<tr>
<td>产品编号
<asp:Label ID="lbl_productid" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Productid")%>'>
</asp:Label></td>
</tr>
<tr>
<td>产品名称
<asp:Label ID="lbl_productname" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ProductName")%>'>
</asp:Label></td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" Runat="server" Text="详细资料" CommandName="allData"></asp:Button></td>
</tr>
</table>
</ItemTemplate>
<EditItemTemplate>
<table>
<tr>
<td>产品编号
<asp:Label ID="Label5" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Productid")%>'>
</asp:Label></td>
</tr>
<tr>
<td>产品名称
<asp:Label ID="Label6" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"ProductName")%>'>
</asp:Label></td>
</tr>
<tr>
<td>单价
<asp:TextBox ID="txt_unitprice" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"UnitPrice")%>'>
</asp:TextBox></td>
</tr>
<tr>
<td>库存量
<asp:TextBox ID="txt_stock" Runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"UnitsInStock")%>'>
</asp:TextBox></td>
</tr>
<tr>
<td>
<asp:Button ID="cmd_save" Runat="server" Text="保存" CommandName="savedata"></asp:Button>
<asp:Button ID="cmd_cancel" Runat="server" Text="取消" CommandName="canceldata"></asp:Button></td>
</tr>
</table>
</EditItemTemplate>
</asp:datalist></form>
</body>
</HTML>
解决方案 »
- |ZYCWPF| 在i:DataTrigger中,如何觖发Click事件,谢谢 有示例代码
- tabcontrol,在第一个tabpage做个搜索按钮,需要进度条,然后结果填充在第二个tabpage
- 大家帮一下我,程序-->数据库还是程序-->服务端-->数据库
- 引用类型转换:派生类为什么可以隐式的转换成基类??
- “int?”这种是什么用法?
- C#实现选择排序,选择排序和冒泡有什么区别
- 求教,关于自定义属性的问题。
- 如何能定时,并按照一定间隔运行一段程序?
- NHibernate问题
- 请问各位c#可以和locus domain/notes配合开发吗?
- CacheItemRemovedCallback的用法,我是这样用的,有没错呢
- oracle9i连接出错,错误提示”必须为此操作打开连接“,望高手解决
da=new DataSet()