1

我想通过 Web 服务将数据从 monodroid 应用程序存储到 sql server。

monodroid ==> Web 服务 ==> Sql 服务器

实际上,我尝试通过 Web 服务使用带有 sql server 的 asp.net。它适用于这种方法。插入sql server的数据。

asp.net ==> 网络服务 ==> sql 服务器。

但是当我为 monodroid 尝试这种类似的方式时,数据尚未存储在 sql server 数据库中。

这是我的 Web 服务代码:

    SqlConnection conn = new SqlConnection(@"Data Source=DINESH-PC\SQLEXPRESS;Initial Catalog=remotedb;Integrated Security=True");
    SqlCommand com;

    public Service1 () {

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
}

    [WebMethod]
    public string insert(string name)
    {
        com = new SqlCommand("insert into dinesh values('" + name + "')", conn);
        conn.Open();
        com.ExecuteNonQuery();
        conn.Close();
        return "Hello World";
    }
}

这是我的 monodroid 代码

public class Activity1 : Activity
{

    localhost.Service1 suresh = new localhost.Service1();
    string dinesh;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button>(Resource.Id.MyButton);

        EditText e1=FindViewById<EditText>(Resource.Id.editText1);
        button.Click += delegate {

            dinesh = suresh.insert(e1.Text);
        };
    }
}

}

帮助我,我需要在编码中更改什么,或者我需要更改任何设置以访问 monodroid 中的 Web 服务吗?

4

0 回答 0