Introduction:
Here I will explain how to solve the problem of “name of field or property being initialized in an object initializer must start with '.'” while converting C# code to vb.net.
Description:
Here I will explain how to solve the problem of “name of field or property being initialized in an object initializer must start with '.'” while converting C# code to vb.net.
Description:
In
previous posts I explained many articles relating to solve errors in asp.net, SQL
Server, IIS, etc. Now I will
explain how to solve the problem of “name
of field or property being initialized in an object initializer must start with
'.'”
while
converting C# code to vb.net.
I
have one foreach loop code in C#
that is like as shown below
C# Code
foreach(DataRow dr in
dt.Rows)
{
countrychart.PieChartValues.Add(new
AjaxControlToolkit.PieChartValue
{
Category = dr["name"].ToString(),
Data = Convert.ToDecimal(dr["total"]),
});
}
|
I tried
to convert C# to vb.net code by using some online
tools once I converted code that will be like as shown below
VB.NET Code
For Each dr As DataRow In dt.Rows
countrychart.PieChartValues.Add(New
AjaxControlToolkit.PieChartValue() With { _
Key.Category = dr("name").ToString(),
_
Key.Data = Convert.ToDecimal(dr("total")) _
})
Next
|
Whenever
I run above code I got error like “name of field or
property being initialized in an object initializer must start with '.'”
I
finally found this error because I used Key
with object initializers. To solve this problem I removed that Key name like as shown below then
everything working fine
For Each dr As DataRow In
dt.Rows
countrychart.PieChartValues.Add(New
AjaxControlToolkit.PieChartValue() With { _
.Category = dr("name").ToString(),
_
.Data = Convert.ToDecimal(dr("total")) _
})
Next
|
I
hope it helps you to solve your problem. Happy Coding……
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.