Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Creating a Class File

Creating a Class File

Scheduled Pinned Locked Moved C#
helptutorial
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChennaiBabu
    wrote on last edited by
    #1

    Hi All, Greetings.I've to create a class file.Here i've added the coding what i've written.But its showing the error.Can any one tell me is this class correct and how to call in my .cs file. public int AddEmployee(string employeeID,string employeeName,string Designation,string Machinetowork,string dateofbirth,string address,string city,string state,string zip,string phoneNo,string MobileNo,string email) { SqlConnection conn = new SqlConnection(conStr); SqlCommand cmd = new SqlCommand("insert into Employee Values(@EmployeeID,@EmployeeName,@Designation,@MachineToWork,@DateOfBirth,@Address,@City,@State,@Zip,@PhoneNumber,@MobileNumber,@Email)",conn); cmd.Parameters.Add("@EmployeeID",employeeID); cmd.Parameters.Add("@EmployeeName",employeeName); cmd.Parameters.Add("@Designation",Designation); cmd.Parameters.Add("@MachineToWork",Machinetowork); cmd.Parameters.Add("@DateOfBirth",dateofbirth); cmd.Parameters.Add("@Address",address); cmd.Parameters.Add("@City",city); cmd.Parameters.Add("@State",state); cmd.Parameters.Add("@Zip",zip); cmd.Parameters.Add("@PhoneNumber",phoneNo); cmd.Parameters.Add("@MobileNumber",MobileNo); cmd.Parameters.Add("@Email",email); int err=1; conn.Open(); { cmd.ExecuteNonQuery(); } conn.Close(); return err; }

    Babu

    C 1 Reply Last reply
    0
    • C ChennaiBabu

      Hi All, Greetings.I've to create a class file.Here i've added the coding what i've written.But its showing the error.Can any one tell me is this class correct and how to call in my .cs file. public int AddEmployee(string employeeID,string employeeName,string Designation,string Machinetowork,string dateofbirth,string address,string city,string state,string zip,string phoneNo,string MobileNo,string email) { SqlConnection conn = new SqlConnection(conStr); SqlCommand cmd = new SqlCommand("insert into Employee Values(@EmployeeID,@EmployeeName,@Designation,@MachineToWork,@DateOfBirth,@Address,@City,@State,@Zip,@PhoneNumber,@MobileNumber,@Email)",conn); cmd.Parameters.Add("@EmployeeID",employeeID); cmd.Parameters.Add("@EmployeeName",employeeName); cmd.Parameters.Add("@Designation",Designation); cmd.Parameters.Add("@MachineToWork",Machinetowork); cmd.Parameters.Add("@DateOfBirth",dateofbirth); cmd.Parameters.Add("@Address",address); cmd.Parameters.Add("@City",city); cmd.Parameters.Add("@State",state); cmd.Parameters.Add("@Zip",zip); cmd.Parameters.Add("@PhoneNumber",phoneNo); cmd.Parameters.Add("@MobileNumber",MobileNo); cmd.Parameters.Add("@Email",email); int err=1; conn.Open(); { cmd.ExecuteNonQuery(); } conn.Close(); return err; }

      Babu

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      ChennaiBabu wrote:

      But its showing the error

      Standard Question #1: What is the error?

      ChennaiBabu wrote:

      Can any one tell me is this class correct and how to call in my .cs file.

      You have not shown a class, you have shown a single method. You do not call a .cs file you intantiate classes then call the methods in the class Might I suggest that you read a beginners book on C# because I get the feeling that if I attempt to answer you it will turn in to a very long thread that could easily be resolved if you just read some introductory information in C#


      * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

      G 1 Reply Last reply
      0
      • C Colin Angus Mackay

        ChennaiBabu wrote:

        But its showing the error

        Standard Question #1: What is the error?

        ChennaiBabu wrote:

        Can any one tell me is this class correct and how to call in my .cs file.

        You have not shown a class, you have shown a single method. You do not call a .cs file you intantiate classes then call the methods in the class Might I suggest that you read a beginners book on C# because I get the feeling that if I attempt to answer you it will turn in to a very long thread that could easily be resolved if you just read some introductory information in C#


        * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Colin Angus Mackay wrote:

        Standard Question #1: What is the error?

        No, that is standard question #2. Standard question #1 is: What do you mean by "not working"? :)

        --- b { font-weight: normal; }

        C 1 Reply Last reply
        0
        • G Guffa

          Colin Angus Mackay wrote:

          Standard Question #1: What is the error?

          No, that is standard question #2. Standard question #1 is: What do you mean by "not working"? :)

          --- b { font-weight: normal; }

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          :doh:


          * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          G 1 Reply Last reply
          0
          • C Colin Angus Mackay

            :doh:


            * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            If you use my standard questions, please use the right ones. :) Here is a complete list of my standard questions: Standard question #1: What do you mean by "not working"? Standard question #2: What error message do you get? Standard question #3: What does your code look like? Standard question #4: No, "nothing" never happens. Exactly what is happening? Standard question #5: No, that is not the code you are using. It can't produce that result. What does the code you are using look like?

            --- b { font-weight: normal; }

            C 1 Reply Last reply
            0
            • G Guffa

              If you use my standard questions, please use the right ones. :) Here is a complete list of my standard questions: Standard question #1: What do you mean by "not working"? Standard question #2: What error message do you get? Standard question #3: What does your code look like? Standard question #4: No, "nothing" never happens. Exactly what is happening? Standard question #5: No, that is not the code you are using. It can't produce that result. What does the code you are using look like?

              --- b { font-weight: normal; }

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              Guffa wrote:

              If you use my standard questions, please use the right ones.

              No problems - I'll copy them onto a postit note for future reference. :-D


              * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups