ウィンドウフォンからWCFを介してSQLサーバーにデータを挿入しようとしています。この例に従ってプロジェクトを編集しました.データを挿入 しましたが、データがデータベースに挿入されません。私のコーディングは次のとおりです。
WindowPhone MainPage.xaml.cs の下に配置されます。
private void button1_Click(object sender, RoutedEventArgs e)
{
//Insert textbox1.text into database
string empId = textBox1.Text;
Service1Client proxy = new Service1Client();
proxy.AddEmployeeCompleted += new EventHandler<AddEmployeeCompletedEventArgs>(proxy_AddEmployeeCompleted);
proxy.AddEmployeeAsync(empId);
MessageBox.Show(textBox1.Text);
}
private void proxy_AddEmployeeCompleted(object sender, AddEmployeeCompletedEventArgs e)
{
bool bb = Convert.ToBoolean(e.Result);
MessageBox.Show(textBox1.Text);
if (bb == true)
{
MessageBox.Show("Record Added Successfully !!");
}
else
{
MessageBox.Show("Unable to Insert record,Try Again !!");
}
}
Service1.svc.cs のコード
namespace MyService
{
public class Service1 : IService1
{
public bool AddEmployee(string empId)
{
try
{
DataClasses1DataContext cont = new DataClasses1DataContext();
MyEmployee data = new MyEmployee();
data.EmpId = empId;
cont.MyEmployees.InsertOnSubmit(data);
cont.SubmitChanges();
return true;
}
catch
{
return false;
}
}
}
}
および IService1.cs のコード
namespace MyService
{
[ServiceContract]
public interface IService1
{
[OperationContract]
bool AddEmployee(string empId);
}
}
私のコーディングに問題はありますか?