0
這是我一直在VB.net中做的事情,我試圖在C#中複製它。基本上我有一個數據集連接到sqlserver,我試圖添加一個新的行。我有以下,但rMainPID似乎爲空。在C#中使用數據集#
private components.db.PIDSDB.MainPIDDataTable dtMainPID;
private components.db.PIDSDBTableAdapters.MainPIDTableAdapter taMainPID = new components.db.PIDSDBTableAdapters.MainPIDTableAdapter();
然後主營:
protected void doSave(object sender, EventArgs e)
{
Int32 ClientID = Convert.ToInt32(txtCompanyClientID.Text);
String ChannelLead = Request.Form["ChannelLead"];
// String ChannelSalesPerson = Request.Form["ChannelSalesPerson"];
String ChannelSalesPerson = "Test";
String DropDeadDate = Request.Form["DropDeadDate"];
String MCSalesLead = Request.Form["MCSalesLead"];
Int32 ProjectTypeID = Convert.ToInt32(Request.Form["ProjectTypeID"]);
Int32 ProjectStatusID = Convert.ToInt32(Request.Form["ProjectStatusID"]);
String ClientBriefing = Request.Form["ClientBriefing"];
String ProjectRequirements = txtProjectRequirements.Text;
components.db.PIDSDB.MainPIDRow rMainPID = default(components.db.PIDSDB.MainPIDRow);
rMainPID = dtMainPID.NewMainPIDRow();
rMainPID.ClientID = (ClientID);
rMainPID.ChannelLead = (ChannelLead);
rMainPID.ChannelSalesPerson = (ChannelSalesPerson);
rMainPID.DropDeadDate = (DropDeadDate);
rMainPID.MCSalesLead = (MCSalesLead);
rMainPID.ProjectTypeID = (ProjectTypeID);
rMainPID.ProjectStatusID = (ProjectStatusID);
rMainPID.ClientBriefing = (ClientBriefing);
rMainPID.ProjectRequirements = (ProjectRequirements);
dtMainPID.AddMainPIDRow(rMainPID);
taMainPID.Update(dtMainPID);
}
dtMainPID爲空,因此你不能用它來返回MainPIDRow –
的新實例,請檢查對象'dtMainPID'什麼或不 –
嗯,是的,我得到的,但我不知道如何解決它 - 它不應該是空的,所以檢查一下它是沒有或不會使錯誤沒有,但它不會做更新。 – TMB87