Hello,
This is a very fast code creation and there could be
some data types minor mistakes. If there are please accept my
apologies. You can create a "Hello world!" web service in C# and then
you have to create another method SetEmployeesDetails (see below) which
will call a stored procedure to do the actual insert.
using System.Data.SqlClient;
using System.Data;
[WebMethod(Description = "Sets employees details")]
public int SetEmployeesDetails(string sEmployeeName, int nEmployeeId, DateTime dtDate )
{
int inRowsAffected;
SqlConnection sqlConnSetEmployeesDetails;
sqlConnSetEmployeesDetails = new SqlConnection("Data
Source=myServerName;Initial Catalog=myDataBase;User
ID=myUser;Password=myPass;");
using (sqlConnSetEmployeesDetails)
{
SqlCommand sqlCmdSetEmployeesDetails = new SqlCommand("myTableIns", sqlConnSetEmployeesDetails);
sqlCmdSetEmployeesDetails.
CommandType = CommandType.StoredProcedure;
sqlCmdSetEmployeesDetails.Parameters.Add(new SqlParameter("@myEmployeeName", SqlDbType.NVarChar, 50));
sqlCmdSetEmployeesDetails.Parameters[0].Value = sEmployeeName;
sqlCmdSetEmployeesDetails.Parameters.Add(new SqlParameter("@myId", SqlDbType.Int));
sqlCmdSetEmployeesDetails.Parameters[1].Value = nEmployeeId;
sqlCmdSetEmployeesDetails.Parameters.Add(new SqlParameter("@myDate", SqlDbType.Datetime));
sqlCmdSetEmployeesDetails.Parameters[2].Value = dtDate;
sqlConnSetEmployeesDetails.Open();
inRowsAffected = sqlCmdSetEmployeesDetails.ExecuteNonQuery();
}
return inRowsAffected;
}
I really hope you will manage to make this code work. Please let me know of your final result.
Have fun,
Bogdan