Results 1 to 4 of 4

Thread: [02/03] Stuck in C# code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Posts
    244

    [02/03] Stuck in C# code

    Hi,
    i am very new to C#.

    Actually i have written these lines of code in class file.But it is giving error.-- near dataset word --Expected Class,enum,structure,delegate, interface,why , what may be the problem, same lines of code in vb.net is working fine.


    Code:
    using System;
    using System.Data;
    using System.Data.SqlClient;
    
    public static DataSet returndataset(string connectionstring, string str)
    {
    SqlConnection con = new SqlConnection(connectionstring);
    DataSet ds = new DataSet();
    SqlCommand cmd = new SqlCommand(str, con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(ds);
    return ds;
    }
    Kindly help me to solve this problem.And suggest some links to study C#.

    Thanks in advance

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Stuck in C# code

    Perhaps the C# forum would be a more appropriate place for this thread. I suggest that you PM a mod and ask them to move it.

    The reason for your error is that you must declare a type before you can declare a member. You've declared a method, which cannot exist on its own. It must be within a type declaration. That's why you're told that it is expecting one of those list of things, all of which are types.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [02/03] Stuck in C# code

    Moved
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] Stuck in C# code

    same lines of code in vb.net is working fine.
    I doubt it.

    To add a class to your project, right click your project, add new, and choose class. It will come 'pre-coded' like a skeleton. In the closet.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width