I'm new to ASP.NET and I'm trying to make a simple forum.
I'm using LINQ to SQL for data access.
I'm trying to insert a new 'Topic' object into my database with the following code, which upon execution gives me the following error "Object reference not set to an instance of an object" on the line "topicDB.insertTopic(inserter);". This seems like an odd error to me seeing as the only object I'm using is clearly initialized and I even put all parameters in a variable beforehand just to make sure. I have verified that the userId and categoryId variables are correctly set.
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
BLTopic topicDB = new BLTopic();
String name = Tit.Text;
String description = "";
if (Description.Text != "")
{
description = Description.Text;
}
int categoryId = Int32.Parse(Request["id"]);
int userId = Int32.Parse(Session["userId"].ToString());
DateTime dateTime = DateTime.Now;
Topic inserter = new Topic();
inserter.Name = name;
inserter.Description = description;
inserter.CategoryId = categoryId;
inserter.UserId = userId;
inserter.PostDate = dateTime;
topicDB.insertTopic(inserter);
}
I'm using LINQ to SQL for data access.
I'm trying to insert a new 'Topic' object into my database with the following code, which upon execution gives me the following error "Object reference not set to an instance of an object" on the line "topicDB.insertTopic(inserter);". This seems like an odd error to me seeing as the only object I'm using is clearly initialized and I even put all parameters in a variable beforehand just to make sure. I have verified that the userId and categoryId variables are correctly set.
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
BLTopic topicDB = new BLTopic();
String name = Tit.Text;
String description = "";
if (Description.Text != "")
{
description = Description.Text;
}
int categoryId = Int32.Parse(Request["id"]);
int userId = Int32.Parse(Session["userId"].ToString());
DateTime dateTime = DateTime.Now;
Topic inserter = new Topic();
inserter.Name = name;
inserter.Description = description;
inserter.CategoryId = categoryId;
inserter.UserId = userId;
inserter.PostDate = dateTime;
topicDB.insertTopic(inserter);
}