question

Simflex-3472 avatar image
0 Votes"
Simflex-3472 asked JiachenLiMFST-9349 edited

Error: BC30369 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

Hi experts,

I have followed the suggested solutions on this forum for this issue on the subject line of this thread but none has a solution to helps my situation.

I have the following function with SHARED method:

Public Shared Function GetDetails(ByVal speakerId As String) As String
Dim context As HttpContext = HttpContext.Current
Dim ds As DataSet = New DataSet()
Dim dt As DataTable = New DataTable("SpeakersData")
Dim constring As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim sqlCon As SqlConnection = New SqlConnection(constring)
Using cmd As SqlCommand = New SqlCommand("SELECT SpeakerId,SpeakerName,Email FROM Speakers WHERE SpeakerId = @SpeakerId", sqlCon)
cmd.Parameters.AddWithValue("@SpeakerId", If(Not String.IsNullOrEmpty(speakerId), speakerId, CObj(DBNull.Value)))
sqlCon.Open()
exampleWrap.Visible = True
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
sda.Fill(dt)
ds.Tables.Add(dt)
End Using
End Using
Return ds.GetXml()
End Function

When I added the exampleWrap.Visible = True to the function, I get the following:

BC30369 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.

When I removed the Shared method from the function as recommended by some suggestions in some of the recommended solutions online, I get

"DataTables warning: table id=exampleData - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1"

Without removing the Shared method and the exampleWrap.Visible = True from the function, the code works.

The only problem is that I wanted to hide the no data found message until user clicks the Submit button.

I am stuck. Any ideas how to work around this?

Many thanks in advance.



dotnet-standard
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Simflex-3472 ,
Could you please provide more information about your project?
What is the no data found message?

0 Votes 0 ·

Hi @Simflex-3472 ,
May I know if you have got any chance to check my reply? It will be great if you can share more detailed information for us to better investigate this issue.

0 Votes 0 ·

0 Answers