Sruthi
Sruthi

Reputation: 69

Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx). error?

I need to save those six fields in same column but not in same row and same cell. each field have default GUID.so i decided to put that default guid's in one list and fields in one list and call that object of that particular list where we want .

       ArrayList Alist = new ArrayList();
        {
            Alist.Add("FD713788-B5AE-49FF-8B2C-F311B9CB0CC4");
            Alist.Add("64B512E7-46AE-4989-A049-A446118099C4");
            Alist.Add("376D45C8-659D-4ACE-B249-CFBF4F231915");
            Alist.Add("59A2449A-C5C6-45B5-AA00-F535D83AD48B");
            Alist.Add("03ADA903-D09A-4F53-8B67-7347A08EDAB1");
            Alist.Add("2F405521-06A0-427C-B9A3-56B8931CFC57");
        }

        ArrayList objValue = new ArrayList();
        {
            objValue.Add(viewmodel.TinNo);
            objValue.Add(viewmodel.CstNo);
            objValue.Add(viewmodel.PanNo);
            objValue.Add(viewmodel.CinNo);
            objValue.Add(viewmodel.ExciseRegNo);
            objValue.Add(viewmodel.ServiceTaxNo);
        }

   var TaxInfoTaxFiledclassobj = new TaxInfoTaxFiled()
        {

            TaxInfoTaxFieldID = TaxInfoTaxFieldObj,
            TaxFieldID = new Guid(Alist .ToString ()),
            FieldValue = objValue.ToString(),
        };

All are working Fine but in TaxFieldID it show the count which has been calculated from list but while saving it show the below error

enter image description here

What shall I do?

Upvotes: 5

Views: 86131

Answers (3)

Amit Kumar Ghosh
Amit Kumar Ghosh

Reputation: 3726

Guid.Parse() is capable of parsing a GUID. Alist.ToString() should not be a GUID.

EDIT

I guess you're looking for something like this -

var listFiled = new List<TaxInfoTaxFiled>();
for(var item = 0; item < objValue.Count ; item++)
{
    listFiled.Add(new TaxInfoTaxFiled
    {

        TaxInfoTaxFieldID = TaxInfoTaxFieldObj,
        TaxFieldID = new Guid(Alist[item]),
        FieldValue = objValue[item]
    });
}

Upvotes: 2

rjv
rjv

Reputation: 6776

AList is an array, not a Guid.

You must be doing Guid.Parse on entries of AList

Something like

foreach(string g in AList)
{
     Guid guid = Guid.Parse(g);
     // Guid guid = new Guid(g) also works
}

Upvotes: 0

Steve
Steve

Reputation: 9593

You're trying to pass an ArrayList as a Guid. In this line:

TaxFieldID = Guid.Parse(Alist.ToString())

You need to select just one of the elements of the ArrayList to parse. Additionally, you could use a List<Guid> to eliminate the problem altogether.

List<Guid> guidList = new List<Guid>();
guidList.Add(new Guid("DDE4BA55-808E-479F-BE8B-72F69913442F"));

...

TaxFieldID = guidList[0]; // obviously, select the appropriate GUID

Upvotes: 3

Related Questions