I am trying to import some records from Access to SQL server using LINQ to SQL, and I received the error in the subject at "select new tblName" (select is underlined) in the following code:
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();
There is another error also at the 2nd last line: The type arguments for method 'System.Data.Linq.Table.InsertAllOnSubmit(System.Collections.Generic.IEnumerable)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Thank you, Steven