[Solved] ASP.Net C# Error: The type or namespace name Collection could not be found

Last Reply 24 days ago By dharmendr

Posted 25 days ago

i convert vb to c# but for collections there is an error

Error1 The type or namespace name 'Collection' could not be found (are you missing a using directive or an assembly reference?

please solve

    public object run_query(Collection data_items, string data_proc, string operation, ref DataTable selectdata, string dbname)
    {
        string ret_value = "Error";
        CommandExecutor CmdExecutor = new CommandExecutor("System.Data.SqlClient", setconnectstring(dbname));
        try
        {
            List<DataPacket> DTList = new List<DataPacket>();
            foreach (var item in data_items)
                DTList.Add(new DataPacket() { FieldName = item(0), FieldValue = item(1), SqlType = item(2), Direction = item(3) });
            switch (operation)
            {
                case "Insert":
                    {
                        ret_value = Convert.ToString(CmdExecutor.ExecuteCommand(DALC.CommandTypes.StoredProcedure, data_proc, DALC.Operation.Insert, DTList));
                        break;
                    }

                case "Update":
                    {
                        ret_value = Convert.ToString(CmdExecutor.ExecuteCommand(DALC.CommandTypes.StoredProcedure, data_proc, DALC.Operation.Update, DTList));
                        break;
                    }

                case "Delete":
                    {
                        ret_value = Convert.ToString(CmdExecutor.ExecuteCommand(DALC.CommandTypes.StoredProcedure, data_proc, DALC.Operation.Delete, DTList));
                        break;
                    }

                case "Select":
                case "All":
                    {
                        selectdata = CmdExecutor.SelectCommand(DALC.CommandTypes.StoredProcedure, data_proc, DALC.Operation.Select, DTList);
                        ret_value = "1";
                        break;
                    }
            }
            if (ret_value == "1")
                ret_value = "Done";
            DTList = null;
        }
        catch (Data.SqlClient.SqlException ex)
        {
            if (ex.Number == "2601" | ex.Number == "2627")
                ret_value = "Data Already Exist";
            else if (ex.Number == "547")
                ret_value = "Record is in use";
            else
                ret_value = ex.Message;
        }
        // Throw ex
        finally
        {
            CmdExecutor = null/* TODO Change to default(_) if this is not a reference type */;
        }
        run_query = ret_value;
    }

vb code

Dim data_items As New Collection
data_items.Add(create_array("sql_string", Sql, SqlDbType.NVarChar, DirectionEnum.input))
run_query(data_items, "string_executer", "Select", worktable, db_name)

 

Posted 24 days ago
dabholkarvaibhav8 says:
public object run_query(Collection data_items, string data_proc, string operation, ref DataTable selectdata, string dbname)

Replace above linre with below code.

public object run_query(System.Collections.ObjectModel.Collection<Test> data_items, string data_proc, string operation, ref DataTable selectdata, string dbname)

Note: Replace Test with return type of create_array.

Example: 

If create_array return type is string then 

System.Collections.ObjectModel.Collection<string> data_items

if int then 

System.Collections.ObjectModel.Collection<int> data_items