这是我的代码:
protected void btnShow_Click(object sender, EventArgs e)
{
foreach (Control control in Panel1.Controls)
{
var textBox = control as TextBox;
if (textBox != null)
{
if (string.IsNullOrEmpty(textBox.Text))
{
textBox.Style["visibility"] = "hidden";
}
// textBox.Enabled = false;
var id = from t in textBox.Text
where t != null
select textBox.ID;
var text = from t in textBox.Text
where t != null
select t;
foreach (var x in id)
{
Model.crossword insert = new Model.crossword();
insert.TextBoxID = x;
daoCrossword.Insert(insert);
}
foreach (var a in text)
{
Model.crossword insert = new Model.crossword();
insert.TextBoxValue = a.ToString();
daoCrossword.Insert(insert);
}
daoCrossword.Save();
}
}
}
daoCrossword 是一个类文件,其中包含 CRUD 代码,我正在使用 EF 来执行此操作,我是新手,它给了我一个错误:System.NullReferenceException:对象引用未设置为对象的实例。
CRUD 类文件(部分):
public void Insert(Model.crossword exe)
{
context.crosswords.AddObject(exe);
}
public void Save()
{
context.SaveChanges();
}