如何从错误中恢复? [英] How to recover from the error?

查看:74
本文介绍了如何从错误中恢复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用LinQ将数据从表单插入数据库时​​出现此错误



当我输入类的对象时(例如:Employee empObj = new Employee())它显示错误。

使用(DataClass1DataContext DcContext = new DataClass1DataContext())
{
ArticleMdl articleObj = new ArticleMdl();
articleObj.Title = TextBox1.Text;
articleObj.Summary = TextBox2.Text;
articleObj.Tags = TextBox3.Text;
articleObj.Image = TextBox4.Text;
articleObj.Category = Convert.ToInt32(RadioButtonList1.SelectedValue);
articleObj.Subcategory = Convert.ToInt32(RadioButtonList2.SelectedValue);

DcContext.tblArticles.InsertOnSubmit(articleObj);
DcContext.SubmitChanges();
Label1.Text =你的文章已保存。;
}





错误1'System.Data.Linq.Table的最佳重载方法匹配.InsertOnSubmit(Linqtosql1.tblArticle)'有一些无效的参数



请回复如何恢复它。



我尝试了什么:



尝试插入直接值到属性。出现相同的错误。

解决方案

您传递给该方法的对象不是或来自类型 TEntity

I'm getting this error while inserting data from my form to database using LinQ

When I enter the object of the class(e.g: Employee empObj = new Employee()) It shows the error.

using (DataClass1DataContext DcContext = new DataClass1DataContext())
                {
                    ArticleMdl articleObj = new ArticleMdl();
                    articleObj.Title = TextBox1.Text;
                    articleObj.Summary = TextBox2.Text;
                    articleObj.Tags = TextBox3.Text;
                    articleObj.Image = TextBox4.Text;
                    articleObj.Category = Convert.ToInt32(RadioButtonList1.SelectedValue);
                    articleObj.Subcategory = Convert.ToInt32(RadioButtonList2.SelectedValue);
                    
                    DcContext.tblArticles.InsertOnSubmit(articleObj);
                    DcContext.SubmitChanges();
                    Label1.Text = "Your article is saved.";
                }



Error 1 The best overloaded method match for 'System.Data.Linq.Table.InsertOnSubmit(Linqtosql1.tblArticle)' has some invalid arguments

Please do reply how to recover it.

What I have tried:

Tried to insert on putting of direct values to the properties. The same error arose.

解决方案

The object you're passing to the method is not of or derived from type TEntity.


这篇关于如何从错误中恢复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆