I am new to ASP.NET but I have 6 years of programming experience. I am encountering the following error: BC30390: 'System.Data.DataRow.Protected Sub New(builder As System.Data.DataRowBuilder)' is not accessible in this context because it is 'Protected'. Here
is my code: <script runat="server"> Sub Page_Load If Not IsPostBack Dim dtblStates As New DataTable Dim drowNewState As New DataRow dtblStates.Columns.Add(New DataColumn("StateName", GetType(String))) dtblStates.Columns.Add(New DataColumn("StateAbb", GetType(String)))
drowNewState = dtblStates.NewRow() drowNewState("StateName") = "California" drowNewState("StateAbb") = "CA" dtblStates.Rows.Add(drowNewState) drowNewState = dtblStates.NewRow() drowNewState("StateName") = "North Carolina" drowNewState("StateAbb") = "CA" dtblStates.Rows.Add(drowNewState)
drowNewState = dtblStates.NewRow() drowNewState("StateName") = "Ohio" drowNewState("StateAbb") = "OH" dtblStates.Rows.Add(drowNewState) radState.DataSource = dtblStates radState.DataTextField = "StateName" radState.DataValueField = "StateAbb" radState.DataBind()
End If End Sub </script> <form runat="server"> </form> Can anyone please explain to me why I am getting this error? I can't seem to find an answer to this anywhere. Thanks for any help.
Change the line: Dim drowNewState As New DataRow to Dim drowNewState As DataRow
putting the 'New' there tries to instantiate the DataRow which can only happen,as you do in your code, by calling DataTable's NewRow method. Therefore you only declare the member and get the instance later by using NewRow.
Thanks for the help. This must be a typo in the book I am using. Once I removed "New", everything is fine. The book clearly states "New" in the declaration of the DataRow. Thanks again.
Yes, it is typo in that case. DataRow does not have public default constructor (or public with arguments) so it cannot be instantiated, it can only with the previously described method.
None
0 Points
2 Posts
DataRow not accessible because it is 'Protected'?
Jan 15, 2004 01:59 PM|Coder123|LINK
Star
10931 Points
6879 Posts
ASPInsiders
MVP
Re: DataRow not accessible because it is 'Protected'?
Jan 15, 2004 02:08 PM|joteke|LINK
Dim drowNewState As New DataRow
toDim drowNewState As DataRow
putting the 'New' there tries to instantiate the DataRow which can only happen,as you do in your code, by calling DataTable's NewRow method. Therefore you only declare the member and get the instance later by using NewRow.Teemu Keiski
Finland, EU
None
0 Points
2 Posts
Re: DataRow not accessible because it is 'Protected'?
Jan 15, 2004 02:13 PM|Coder123|LINK
Star
10931 Points
6879 Posts
ASPInsiders
MVP
Re: DataRow not accessible because it is 'Protected'?
Jan 15, 2004 02:21 PM|joteke|LINK
Teemu Keiski
Finland, EU