【发布时间】:2013-11-07 02:39:49
【问题描述】:
我正在尝试使用 LINQ to SQL 将一些记录从 Access 导入 SQL 服务器,并且在以下代码中的“选择新 tblName”(选择带有下划线)处收到了主题中的错误:
OdbcConnection myconnection = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=" + this.txtFullPath.Text);
OdbcDataAdapter myadapter = new OdbcDataAdapter("SELECT * FROM Name", myconnection);
DataSet myCustomersDS = new DataSet();
myadapter.Fill(myCustomersDS, "Name");
//LINQ
iMISDataContext db = new iMISDataContext();
// inserting multiple items
tblName toInsert =
from row in myCustomersDS.Tables["Name"].AsEnumerable()
select new tblName
{
ID = row.Field<string>("ID"),
ORG_CODE = row.Field<string>("ORG_CODE"),
MEMBER_TYPE = row.Field<string>("MEMBER_TYPE"),
//... and rest of the columns (lots of columns)
};
db.tblNames.InsertAllOnSubmit(toInsert);
db.SubmitChanges();
最后第二行还有另一个错误: 无法从用法中推断方法“System.Data.Linq.Table.InsertAllOnSubmit(System.Collections.Generic.IEnumerable)”的类型参数。尝试明确指定类型参数。
谢谢你, 史蒂文
【问题讨论】:
-
InsertAllOnSubmit的签名是什么?