“/WebApplicationCSharp”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
行 152:
行 153:            Label label1=(Label)e.Item.FindControl("CUID");
行 154: string labelValue = label1.Text;
行 155: TextBox CurrentTextBox = (TextBox)e.Item.FindControl("Gender");
行 156: string ColValue = CurrentTextBox.Text;
 源文件: c:\wk\webapplicationcsharp\new_mould.aspx.cs    行: 154   
<asp:Label id="CUID" runat="server"></asp:Label>
这里的CUID文本是通过这个语句获得的:   CUID.Text="CT"+(string)dr["CU_NAME_SHORT"]+yy+noid;public void UidList_SelectedIndexChanged语句是正确的.
public void DataGrid1_Update语句是错误.
public void UidList_SelectedIndexChanged(object sender, System.EventArgs e)
{

           int ids=int.Parse(UidList.SelectedItem.Value);         OracleConnection conn=new OracleConnection("Data Source=WK;user id=wk;password=yourpassword");
string mySelectQuery = "SELECT * FROM customer where id=:id";
OracleCommand myCommand = new OracleCommand(mySelectQuery,conn);
 myCommand.Parameters.Add(":id", OracleType.Int32).Value = ids;
conn.Open(); OracleDataReader dr = myCommand.ExecuteReader(CommandBehavior.SingleRow);
if (dr.Read())
{

string    ddd = (Convert.ToInt32(dr["NO"])+1).ToString();
string noid=ddd.PadLeft(2, '0');
string yy=DateTime.Now.ToString().Substring(2,2);
CUID.Text="CT"+(string)dr["CU_NAME_SHORT"]+yy+noid;
//;
}
dr.Close();
conn.Close();

}
public void DataGrid1_Update(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string keyid = this.DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
     OracleConnection conn=new OracleConnection("Data Source=WK;user id=wk;password=yourpassword");            Label label1=(Label)e.Item.FindControl("CUID");
string labelValue = label1.Text;
TextBox CurrentTextBox = (TextBox)e.Item.FindControl("Gender");
string ColValue = CurrentTextBox.Text;
TextBox CurrentTextBox1 = (TextBox)e.Item.FindControl("cavity");
string cavityValue = CurrentTextBox1.Text;
        
DropDownList DepartmentDropList = (DropDownList)e.Item.FindControl("Dropdownlist1");
int cavpricetypes=int.Parse(DepartmentDropList.SelectedItem.Value);

if(keyid != null && keyid != "")
{

Cmd = "UPDATE quote set NAME=:NAME,CAVITYNO=:CAVITYNO,PRICE_TYPE=:PRICE_TYPE where QUOTE_ID=:QUOTE_ID and no=:NO";


} else
{ Cmd = "insert into quote (QUOTE_ID,NO,NAME,CAVITYNO,PRICE_TYPE) values(:QUOTE_ID,:NO,:NAME,:CAVITYNO,:PRICE_TYPE)";


} OracleCommand myCommand=new OracleCommand(Cmd,conn);
myCommand.Parameters.Add("NO", OracleType.Int32).Value=DataGrid1.DataKeys[e.Item.ItemIndex];
myCommand.Parameters.Add("NAME", OracleType.VarChar, 50).Value = ColValue;
myCommand.Parameters.Add("CAVITYNO", OracleType.VarChar, 20).Value = cavityValue;
myCommand.Parameters.Add("PRICE_TYPE", OracleType.Int32).Value = cavpricetypes;
myCommand.Parameters.Add("QUOTE_ID", OracleType.VarChar, 20).Value = labelValue;
myCommand.Connection.Open();
myCommand.ExecuteNonQuery();
DataGrid1.EditItemIndex = -1;
myCommand.Connection.Close();
BindGridToSource(); }