none
DataView troubles RRS feed

  • Question

  • I'm trying to compile the code:

    using

     

    System;

    using

     

    System.Collections.Generic;

    using

     

    System.Linq;

    using

     

    System.Text;

    using

     

    System.Data;

    namespace

     

    DataView

    {

     

    class Program

    {

     

    static void Main(string[] args)

    {

     

    }

     

    static private void DemonstrateRowState()

    {

     

    // Create a DataTable with one column.

     

    DataTable dataTable = new DataTable("dataTable");

     

    DataColumn dataColumn = new DataColumn("dataColumn");

    dataTable.Columns.Add(dataColumn);

     

    // Add ten rows.

     

    DataRow dataRow;

     

    for (int i = 0; i < 10; i++)

    {

    dataRow = dataTable.NewRow();

    dataRow[

    "dataColumn"] = "item " + i;

    dataTable.Rows.Add(dataRow);

    }

    dataTable.AcceptChanges();

     

    // Create a DataView with the table.

    DataView dataView =

    new DataView(dataTable);

     

    I have the compilation error on the line:  DataView dataView = new DataView(dataTable);

    Error: DataView is a 'namespace' but is used like a 'type'

    How can fix it?

    Tuesday, March 30, 2010 7:36 AM

Answers

  • Hello,

    As Manish and Miha pointed, your namespace is named DataView and you are using System.Data, the compiler first looks at your namespace and DataView is a Namespace but your are trying to use it as the class contained in System.Data. You can either rename your namespace or use System.Data.DataView as Manish mentioned.

    Please let me know if this helps,

    Thanks

    Juan


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, March 31, 2010 2:18 AM
    Moderator

All replies

  • system.data.dataview dataView = new system.data.dataview(dataTable);

    you are using dataview namespace in your project so either change that or use as above


    Manish Sati
    Tuesday, March 30, 2010 7:57 AM
  • Or even global::System.Data.DataView which is a bit more error prone.
    Miha Markic [MVP C#] http://blog.rthand.com
    Tuesday, March 30, 2010 8:20 AM
  • Hello,

    As Manish and Miha pointed, your namespace is named DataView and you are using System.Data, the compiler first looks at your namespace and DataView is a Namespace but your are trying to use it as the class contained in System.Data. You can either rename your namespace or use System.Data.DataView as Manish mentioned.

    Please let me know if this helps,

    Thanks

    Juan


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Wednesday, March 31, 2010 2:18 AM
    Moderator