# Help needed for C# program in VS 2010



## Sharad Sankan (Jul 6, 2011)

ray: I have 22 errors in this program, anyone kindly help to correct.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestTable2
{
classProgram
{
staticvoid Main(string[] args)
{
using (SAPContext sc = newSAPContext(username, password))
{
　
DataSet ds = new DataSet("LinqToSAP");
ds.Locale = System.Globalization.CultureInfo.InvariantCulture;
var customerQuery = from c in sc.KNA1List
where c.LAND1 == "DE"
select c;
DataTable customerTable = customerQuery.ToADOTable(rec => newobject[] { customerQuery });
customerTable.TableName = "Customers";
ds.Tables.Add(customerTable);
var salesHeaderQuery = from s in sc.VBAKList
where s.WAERK == "DEM" || s.WAERK == "EUR"
select s;
DataTable salesHeaderTable = salesHeaderQuery.ToADOTable(rec => newobject[] { salesHeaderQuery });
salesHeaderTable.TableName = "SalesHeader";
ds.Tables.Add(salesHeaderTable);
DataRelation rel = new DataRelation(
"CustomerSalesRelation",
ds.Tables["Customers"].Columns["KUNNR"],
ds.Tables["SalesHeader"].Columns["KUNNR"], false);
ds.Relations.Add(rel);
var salesItemsQuery = from i in sc.VBAPList
where i.WAERK == "DEM" || i.WAERK == "EUR"
select i;
DataTable salesItemsTable = salesItemsQuery.ToADOTable(rec => newobject[] { salesItemsQuery });
salesItemsTable.TableName = "SalesItems";
ds.Tables.Add(salesItemsTable);
DataRelation rel2 = new DataRelation(
"SalesItemsRelation",
ds.Tables["SalesHeader"].Columns["VBELN"],
ds.Tables["SalesItems"].Columns["VBELN"], false);
ds.Relations.Add(rel2);
customerbs.DataSource = ds;
customerbs.DataMember = "Customers";
salesHeaderbs.DataSource = customerbs;
salesHeaderbs.DataMember = "CustomerSalesRelation";
salesItemsbs.DataSource = salesHeaderbs;
salesItemsbs.DataMember = "SalesItemsRelation";
}
}
}
}


Errors:
1) The name 'username' does not exist in the current context C:\Users\MY\documents\visual studio 2010\Projects\TestTable2\TestTable2\Program.cs. Similarly for 'password','customerbs','salesHeaderbs','salesItemsbs','',''



2) 'System.Linq.IQueryable' does not contain a definition for 'ToADOTable' and no extension method 'ToADOTable' accepting a first argument of type 'System.Linq.IQueryable' could be found (are you missing a using directive or an assembly reference?). Similarly Error for tables KNA1 & VBAK.

3) The type or namespace name 'DataSet' could not be found (are you missing a using directive or an assembly reference?) Similarly for 'DataTable' & 'DataRelation'.

Please Help me Correct with these Error messages.
Thank You very much.
-Sharad


----------



## crashmaster (Apr 5, 2007)

Hi,

I think you need to declare a variable before using it...


----------



## Emphyrio (May 16, 2009)

Hi Sharad,

At first blink I see a lot of typos (trimmed spaces) , like :


```
classProgram >>> class Program
staticvoid >>> static void
newobject[]  >>> new object
```



> 3) The type or namespace name 'DataSet' could not be found (are you missing a using directive or an assembly reference?) Similarly for 'DataTable' & 'DataRelation'.


U need the System.Data namespace, so put that in.

```
using System.Data;
```
Further more, here is the exact project where you are working on :

LinqToERP: LINQ to SAP with ERPConnect and Visual Studio 2010 

Hope this helps


----------

