Reputation: 69
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
What shall I do?
Upvotes: 5
Views: 86131
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
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
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