主题:新人请教一个问题 关于asp.net的
syrenq
[专家分:0] 发布于 2006-01-10 22:36:00
“/ren”应用程序中的服务器错误。
--------------------------------------------------------------------------------
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 187: comm.CommandType =CommandType .StoredProcedure ;
行 188: comm.Parameters .Add ( new SqlParameter("@SGID",SqlDbType.Int) );
行 189: comm.Parameters ["@SGID"].Value =Convert.ToInt32 (ddl_gid .SelectedItem.Value.ToString());
行 190: SqlDataReader dr=comm.ExecuteReader ();
行 191: if(dr.Read ())//存在对应项
源文件: c:\inetpub\wwwroot\ren\goodsreserve.aspx.cs 行: 189
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
WMS.GoodsReserve.BindTextBox() in c:\inetpub\wwwroot\ren\goodsreserve.aspx.cs:189
WMS.GoodsReserve.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\ren\goodsreserve.aspx.cs:59
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
老是出现这个问题 我个人感觉我的程序没有问题 为什么老出现这个问题呢
请高手指教下
回复列表 (共5个回复)
沙发
syrenq [专家分:0] 发布于 2006-01-10 22:40:00
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;
using System.Data .SqlClient ;
namespace WMS
{
/// <summary>
/// GoodsReserve 的摘要说明。
/// </summary>
public class GoodsReserve : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddl_gid;
protected System.Web.UI.WebControls.TextBox tbx_squantity;
protected System.Web.UI.WebControls.TextBox tbx_stopline;
protected System.Web.UI.WebControls.TextBox tbx_maxout;
protected System.Web.UI.WebControls.TextBox tbx_maxin;
protected System.Web.UI.WebControls.RadioButton rbn_in;
protected System.Web.UI.WebControls.RadioButton rbn_out;
protected System.Web.UI.WebControls.TextBox tbx_quantity;
protected System.Web.UI.WebControls.RangeValidator rv_quantity;
protected System.Web.UI.WebControls.TextBox tbx_handler;
protected System.Web.UI.WebControls.RequiredFieldValidator rfv_handler;
protected System.Web.UI.WebControls.Button btn_submit;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
//从文件Web.config中读取连接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//绑定货物信息
//连接本地计算机的WMS数据库
SqlConnection cn1= new SqlConnection (strconn);
cn1.Open ();
//SQL语句,找出所有存放在当前用户工作仓库的所有货品
string mysql="select * from goods,store where sgid=gid and swid="+Session["udep"].ToString()+"order by gid desc";
SqlCommand cm1=new SqlCommand (mysql,cn1);
SqlDataReader dr1=cm1.ExecuteReader ();
while(dr1.Read ())
{
ddl_gid.Items.Add (new ListItem(dr1["gname"].ToString(),dr1["gid"].ToString()) );
}
cn1.Close ();
BindTextBox();
}
}
板凳
syrenq [专家分:0] 发布于 2006-01-10 22:44:00
private void ddl_gid_SelectedIndexChanged(object sender, System.EventArgs e)
{
BindTextBox();
}
private void btn_submit_Click(object sender, System.EventArgs e)
{
if(Page.IsValid )
{//从文件Web.config中读取连接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//连接本地计算机的WMS数据库
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
//以下对Store表中的物品数量进行改变
//利用Command对象调用存储过程
SqlCommand cm=new SqlCommand ("storereservemodify",cn);
//将命令类型转为存储类型
cm.CommandType =CommandType.StoredProcedure ;
//往存储过程中添加参数
cm.Parameters .Add ("@SGID",SqlDbType.Int );
cm.Parameters .Add ("@SWID",SqlDbType.Int );
cm.Parameters .Add ("@SQuantity",SqlDbType.Float );
//给存储过程的参数付值
cm.Parameters ["@SGID"].Value =ddl_gid.SelectedItem .Value .ToString ();
cm.Parameters ["@SWID"].Value =Session["udep"] .ToString ();
3 楼
syrenq [专家分:0] 发布于 2006-01-10 22:44:00
if(rbn_in.Checked )//货物入仓
{
cm.Parameters ["@SQuantity"].Value =Convert.ToDouble (tbx_squantity.Text .ToString ())+Convert.ToDouble (tbx_quantity.Text .ToString ());
}
if(rbn_out.Checked )//货物出仓
{
cm.Parameters ["@SQuantity"].Value =Convert.ToDouble (tbx_squantity.Text .ToString ())-Convert.ToDouble (tbx_quantity.Text .ToString ());
}
cm.ExecuteNonQuery ();
//关闭连接
cn.Close();
//以下往仓库进出货物纪录表中增加数据
SqlConnection cn1= new SqlConnection (strconn);
cn1.Open ();
SqlCommand cm1=new SqlCommand ("recordsadd",cn1);
cm1.CommandType =CommandType.StoredProcedure ;
cm1.Parameters .Add ("@RGID",SqlDbType.Int );
cm1.Parameters .Add ("@RWID",SqlDbType.Int );
cm1.Parameters .Add ("@RQuantity",SqlDbType.Float );
cm1.Parameters .Add ("@RType",SqlDbType.Bit );
cm1.Parameters .Add ("@RManager",SqlDbType.VarChar );
cm1.Parameters .Add ("@RDate",SqlDbType.DateTime );
cm1.Parameters .Add ("@RHandler",SqlDbType.VarChar );
cm1.Parameters ["@RGID"].Value =ddl_gid.SelectedItem .Value .ToString ();
cm1.Parameters ["@RWID"].Value =Session["udep"] .ToString ();
cm1.Parameters ["@RQuantity"].Value =tbx_quantity.Text .ToString ();
if(rbn_in.Checked )//货物入仓,设1
{
cm1.Parameters ["@RType"].Value =1;
}
if(rbn_out.Checked )//货物出仓。设0
{
cm1.Parameters ["@RType"].Value =0;
}
cm1.Parameters ["@RManager"].Value =Session["UID"] .ToString ();
cm1.Parameters ["@RDate"].Value =System.DateTime .Now;
cm1.Parameters ["@RHandler"].Value =tbx_handler.Text .ToString ();
cm1.ExecuteNonQuery ();
BindTextBox();
}
}
4 楼
syrenq [专家分:0] 发布于 2006-01-10 22:44:00
private void rbn_out_CheckedChanged(object sender, System.EventArgs e)
{
if(rbn_in.Checked )//货物入仓
{
rv_quantity.MaximumValue =tbx_maxin.Text.ToString ();
}
if(rbn_out.Checked )//货物出仓
{
rv_quantity.MaximumValue =tbx_maxout.Text.ToString ();
}
}
private void rbn_in_CheckedChanged(object sender, System.EventArgs e)
{
if(rbn_in.Checked )//货物入仓
{
rv_quantity.MaximumValue =tbx_maxin.Text.ToString ();
}
if(rbn_out.Checked )//货物出仓
{
rv_quantity.MaximumValue =tbx_maxout.Text.ToString ();
}
}
public void BindTextBox()
{
//从文件Web.config中读取连接字符串
string strconn= ConfigurationSettings.AppSettings["dsn"];
//连接本地计算机的WMS数据库
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
SqlCommand comm=new SqlCommand ("storedetail",cn);
comm.CommandType =CommandType .StoredProcedure ;
comm.Parameters .Add ( new SqlParameter("@SGID",SqlDbType.Int) );
comm.Parameters ["@SGID"].Value =Convert.ToInt32 (ddl_gid .SelectedItem.Value.ToString());
SqlDataReader dr=comm.ExecuteReader ();
if(dr.Read ())//存在对应项
{
tbx_stopline.Text =dr["stopline"].ToString ();
tbx_squantity.Text =dr["squantity"].ToString ();
tbx_maxout.Text=dr["squantity"].ToString ();
tbx_maxin.Text=Convert.ToString (Convert.ToDouble (dr["stopline"].ToString ())-Convert.ToDouble (dr["squantity"].ToString ()));
}
else
{
Response.Write ("对不起,没有该产品信息");
Response.End ();
}
if(rbn_in.Checked )//货物入仓
{
rv_quantity.MaximumValue =tbx_maxin.Text.ToString ();
}
if(rbn_out.Checked )//货物出仓
{
rv_quantity.MaximumValue =tbx_maxout.Text.ToString ();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("Default.aspx");
}
private void Button2_Click(object sender, System.EventArgs e)
{
Response.Redirect("PasswordModify.aspx");
}
}
}
5 楼
syrenq [专家分:0] 发布于 2006-01-10 22:45:00
这个是那个页面的cs代码
这个页面是由登陆页面转过来的
我设置的有3种用户 这个页面的是第2中权限的用户 第1 3权限的用户登陆都正常 唯有这个一登陆就出现这种问题 希望高手能帮我解答下
我来回复