Creating a Class File
-
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
-
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
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
-
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
-
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; }
-
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; }
-
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; }
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