ok, I'm asking another question now....

Previously I had code to add the requester and asignee emails, if the are both empty then I need to build the list. Here is my code:

private string BuildUserList(int p_intSendToRoleID)
{
    
    DataSet dstUsers = new DataSet();
    DataRow drwData = default(DataRow);
    string strUserList = null;
    
    try 
    {
        dstUsers = User.GetUsersByRole(p_intSendToRoleID);
        
        foreach ( drwData in dstUsers.Tables(0).Rows) 
        {
            strUserList += (string)(Information.IsDBNull(drwData("Email")) ? "" : Convert.ToString(drwData("Email")) + ";");
        }
        
        return strUserList;
    }
    
    catch (Exception ex) 
    {
        throw;
    }
    
}

private string BuildUserList(int p_intSendToRoleID) gives me an error at string and
DataSet dstUsers = new DataSet(); gives me an error at DataSet()
both errors are:"Expected class, delegate, enum, interface, or struct"

and I get "Type or namespace definition, or end-of-file expected" at the last bracket.

I'm stuck again - can anyone help me understand?

Recommended Answers

All 6 Replies

Is that your entire code file? You don't seem to have neither a namespace nor a class defined, both of which are needed.

aaargh

scru - I sent you the entire class in pm I don't normally do that but explain why in the message. . .

ddanbe,


it's probably me - I've used VB.Net at work but we are switching to C# and I have to get better at the differences.

In VB.Net I had

Private Function BuildUserList(ByVal p_intSendToRoleID As Integer) As String

        Dim dstUsers As New DataSet
        Dim drwData As DataRow
        Dim strUserList As String

        Try
            dstUsers = User.GetUsersByRole(p_intSendToRoleID)

            For Each drwData In dstUsers.Tables(0).Rows
                strUserList &= CStr(IIf(IsDBNull(drwData("Email")), "", Convert.ToString(drwData("Email")) & ";"))
            Next

            Return strUserList

        Catch ex As Exception
            Throw
        End Try

    End Function

it filled the dataset when calling the User class . . .

will C# not fill it with:
dstUsers = User.GetUsersByRole(p_intSendToRoleID);

>You don't seem to have neither a namespace nor a class defined, both of which are needed.
A namespace isn't required, but for obvious reasons at least one class is.

commented: You are right. +4

Thanks guys,

I had them both declared - I had the brackets misaligned . . . hard to get used to those things after not using them in VB.Net . . .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.