我经常收到此错误,但并非每次都收到此错误。
Object reference not set to an instance of an object.
我正在使用以下代码:
Category n = new Category {
ID = id,
name = TxtName.Text,
TopNav = Convert.ToInt32(Chk_Top.SelectedItem.Value),
LeftNav = Convert.ToByte(Chk_Left.Checked ? "1" : "0"),
Active = Convert.ToByte(Chk_Active.Checked ? "1" : "0"),
Rank = Convert.ToInt32(Txt_position.Text),
ParentID = pid,
Image = name,
Content = Content.Text,
PageTitle = Txt_SpeakerTitle.Text,
PageName = Txt_SpeakerTitle.Text,
speakerpreview = Txt_Previewdesc.Text,
PageDesc = Txt_SpeakerTitle.Text,
PageKeyword = Txt_SpeakerTitle.Text,
Filehandler = "speaker",
SpeakerDetail = speakerdesc.Text,
SpeakerTitle = Txt_SpeakerTitle.Text,
SpotLightdesc = spotlightcontent.Text,
Chk_Spot = Convert.ToByte(Chk_Spot.Checked ? "1" : "0"),
Catalogue = Catalogue };
db.Categories.InsertOnSubmit(n);
请建议。提前致谢。