'dataclassesdatacontext' could not be found
-
Thursday, September 06, 2012 6:41 PM
Friends,
Now i am in situation to transfer the Excel Data (Specific Cell's Data) to SQL. In connection I was used the following statement.
DataClassesDataContext conLinq = new DataClassesDataContext("Data Source=server name;Initial Catalog=Database Name;Integrated Security=true");
I had used "using System.Data.Linq;"
And I had add assembly in .NET Tab also....
But still i am facing following error,
"the type or namespace name 'dataclassesdatacontext' could not be found"
Please help to resolve this issue.
Regards,
Guna
- Moved by Jason Dot WangMicrosoft Contingent Staff Monday, September 10, 2012 6:34 AM This thread is about LINQ to SQL (From:Visual C# Language)
All Replies
-
Thursday, September 06, 2012 6:48 PM
You need to add the reference in the project. Add > Reference> .NET > System.Data.Linq and you will have access to DataContext.
Just additionally, DataClassesDataContext NOT exist in this dll.
Web Developer
- Edited by NorkkMicrosoft Community Contributor Thursday, September 06, 2012 6:52 PM
- Proposed As Answer by Akayster Thursday, September 06, 2012 7:04 PM
-
Thursday, September 06, 2012 6:58 PM
Hello Guna, There is no class by name dataclassesdatacontext in linq DLL. I think you are trying to create object of DBML class. Do you have DBML file?
If not try to create one with the name dataclasses then it would create datacontext class by name dataclassesdatacontext
http://msdn.microsoft.com/en-us/library/bb384470.aspx
please Mark as the Answer, If this answers your question. If this post is helpful, please vote as helpful.
-
Friday, September 07, 2012 5:34 PM
Please see my code below and give your suggestion to use dataclassesdatacontext..
-
Friday, September 07, 2012 9:04 PM
I think you're confusing a couple of different things. DataContext classes are used with LINQ to SQL. If you're not using LINQ to SQL in your application, you will not have one of those data context classes. Note this means more than just using the Linq DLL - you can take a look at that link for information on what L2S involves.
If all you want to do is execute a query, you can make life much easier using a SqlCommand. Something like this:
using (var conn = new SqlConnection("Data Source=server;Initial Catalog=dbName;Integrated Security=true")) { //Put your existing code for loading your data table here. for (int i=0; i < dtExcel.Rows.Count; i++) { var cmd = new SqlCommand("INSERT INTO MyTable VALUES (@value1, @value2, @value3, @value4)"); cmd.Parameters.AddWithValue("value1", dtExcel.Rows[i][0]); cmd.Parameters.AddWithValue("value2", dtExcel.Rows[i][1]); cmd.Parameters.AddWithValue("value3", dtExcel.Rows[i][2]); cmd.Parameters.AddWithValue("value4", dtExcel.Rows[i][3]); cmd.ExecuteNonQuery(); } }
-
Saturday, September 08, 2012 6:17 PM
Dear Friend,
Thanks for your reply.
I need to insert the values (highlighted as red). Please find the picture.
How can i give the cells address in insert command?
Thanks in advance.
Regards,
Guna
- Edited by Gunapriyan Sunday, September 09, 2012 3:37 PM
-
Monday, September 10, 2012 6:33 AM
Hi Gunapriyan,
Welcome to MSDN Forum Support.
You are more likely to get more efficient responses to LINQ to SQL Development issues at http://social.msdn.microsoft.com/Forums/en-US/linqtosql/threads where you can contact LINQ to SQL Development experts,so I would like to redirect you to appropriate forum for better responses.
Sincerely,
Jason Wang
Jason Wang [MSFT]
MSDN Community Support | Feedback to us
-
Monday, September 10, 2012 8:17 AM
Hi Guna,
Welcome to the MSDN forum!
Regarding the structure of the data in the excel worksheet, it is hard to implement the insert via SQL statement directly. However, we can use the Update statement to 'insert' the data. We need to make sure that there are some data in the A5: G5 at first.
Then we can try the following code:
using System.Data.OleDb; namespace TestInsertSpecifiedCells { class Program { static void Main(string[] args) { string sql = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\00-Excel\\TestData.xlsx;Extended Properties='Excel 12.0 Xml;HDR=No';"; OleDbConnection Con = new System.Data.OleDb.OleDbConnection(sql); OleDbCommand cmd = new OleDbCommand(); Con.Open(); cmd.Connection = Con; cmd.CommandText = "Update [Sheet1$A1:B1] Set F2='8545'"; cmd.ExecuteNonQuery(); cmd.CommandText = "Update [Sheet1$A5:G5] Set F1='18000',F2='5',F3='7800',F4='0',F5='0',F6='18000',F7='18000'"; cmd.ExecuteNonQuery(); Con.Close(); } } }
However, to make it easier, namely regardless of the existence of data in A5:G5, I'd like to use Excel automation to implement it.
Please take a look at the following solution:
Note: Please remember to add the reference for the library for excel at first.
using Excel = Microsoft.Office.Interop.Excel; namespace PIAVersion { class Program { static void Main(string[] args) { Object oFalse =false; Excel.Application oExcel = new Excel.Application(); Excel.Workbook oWB = oExcel.Workbooks.Open("D:\\00-Excel\\TestData.xlsx",ReadOnly:oFalse); oExcel.Visible=false; Excel.Worksheet oWS = oWB.Worksheets[1]; oWS.Cells[1, 2] = "8545"; oWS.Cells[5, 1] = "18000"; oWS.Cells[5, 2] = "15"; oWS.Cells[5, 3] = "7800"; oWS.Cells[5, 4] = "0"; oWS.Cells[5, 5] = "0"; oWS.Cells[5, 6] = "18000"; oWS.Cells[5, 7] = "18000"; oWB.Save(); oWB.Close(); oExcel.Quit(); oWS = null; oWB = null; oExcel = null; GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } } }Have a nice day.
Yoyo Jiang[MSFT]
MSDN Community Support | Feedback to us
-
Monday, September 10, 2012 12:07 PM
Dear Mr.Yoyo Jiang,
Thanks for your good reply.
But i didn't understand the following two lines...
cmd.CommandText = "Update [Sheet1$A1:B1] Set F2='8545'"; cmd.CommandText = "Update [Sheet1$A5:G5] Set F1='18000',F2='5',F3='7800',F4='0',F5='0',F6='18000',F7='18000'";
All the values are dynamic in excel sheet.
Because i will circulate the excel file to many clients. They will enter different values and they have to upload the same.
But Cell location never change and values will be there.
Need assistance.....
And how can i use "where" condition in that "Update" statement?
Thanks in advance.
Regards,
Guna
- Edited by Gunapriyan Monday, September 10, 2012 5:03 PM
- Edited by Gunapriyan Monday, September 10, 2012 5:13 PM
- Edited by Gunapriyan Tuesday, September 11, 2012 4:42 AM
- Edited by Gunapriyan Tuesday, September 11, 2012 5:29 PM
-
Friday, September 14, 2012 4:58 PM
Dear Mr.Yoyo Jiang,
Good Evening.
I am waiting for your reply.
Please help me to sort out my problem.
Regards,
Guna
-
Saturday, September 15, 2012 5:24 PM
Dear Friends,
Sorry to ask once again.
Please help me to sort out my problem.
Regards,
Guna

