protected void ButtonAddDatabase_Click(object sender, EventArgs e)
{
using (KnowItCvdbEntities db = new KnowItCvdbEntities())
{
SPWeb theSite = SPControl.GetContextWeb(Context);
SPUser theUser = theSite.CurrentUser;
string strUserName = theUser.LoginName;
var theEmplDbSkill = (
from p
in db.EMPLOYEES
where p.username == strUserName
select p).FirstOrDefault();
_emp = theEmplDbSkill;
if (_emp != null)
{
foreach (var vItem in ListBoxDatabases.Items)
{
if (ValueAlreadyInListDb(vItem))
return;
}
//Get existing skilllevel from db
var skillLevel = (from sL in db.TECHNICAL_SKILL_LEVEL
where sL.technical_skill_level_id == Convert.ToInt32(DropDownListDB.SelectedValue)
select sL).FirstOrDefault();
//Get existing skillvalue from db
var skillValue = (from sV in db.TECHNICAL_SKILLS
where sV.technical_skill_id == Convert.ToInt32(RadioButtonListDatabase.SelectedValue)
select sV).FirstOrDefault();
//Adding to employees_technical_skills table
var empSkill = new EMPLOYEES_TECHNICAL_SKILLS
{
technical_skill_id = Convert.ToInt32(DropDownListDB.SelectedItem.Value),
TECHNICAL_SKILLS = skillValue,
technical_skill_level_id = Convert.ToInt32(RadioButtonListDatabase.SelectedItem.Value)
TECHNICAL_SKILL_LEVEL = skillLevel,
employee_id = _emp.employee_id
}
_emp.EMPLOYEES_TECHNICAL_SKILLS_Add(empSkill);
db.SaveChanges();
_emp.EMPLOYEES_TECHNICAL_SKILLS.Add(empSkill);
db.SaveChanges();
}
}
}
现在我正在下面的表格填充: 无法填充数据库表
这是我的表:
但我不断收到错误:
LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression.
Regards, Kristian。
只是建议,你需要遵循C#编码约定 – 2013-03-27 15:19:46
你确认'technical_skill_level_id'属性有一个合法的值吗?从错误中看来,这个值不是'TECHNICAL_SKILL_LEVEL'表中的值。也许下拉值都是零而不是正确的值。 – 2013-03-27 15:20:34
@CongLong,我确实把我的C#代码放在上面,我应该放更多? – Kriistiian 2013-03-27 15:20:35