Azure移动服务:无法在表中插入任何记录? [英] Azure Mobile Service: Cannot insert any records to table?

查看:63
本文介绍了Azure移动服务:无法在表中插入任何记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个Azure移动服务并正确设置了所有数据库表(对其进行了测试).但是,当我尝试通过Android应用将记录插入到SQL表中时,不会添加该记录. (是的,我的SQL表也可以用于移动服务.也更改了架构)

I created an azure mobile service and set up all the database tables properly (tested them). However when I try to insert a record to my SQL table through my android app, the record doesn't get added. (Yes my SQL table is ready for the mobile service as well. Changed the Schema as well)

我也没有收到错误消息.

I don't get an error either.

这是我的代码:

@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_screen);

        final String mobileServiceUrl =
                "https://MY_AZURE_MOBILE_URL.net/tables/UserTable";
        final String mobileServiceAppId =
                "MY_MOBILESERVICE_APPID";


        try {
            // Create the Mobile Service Client instance, using the provided
            // Mobile Service URL and key
            mClient = new MobileServiceClient(
                    mobileServiceUrl,
                    mobileServiceAppId,
                    this);

            // Get the Mobile Service Table instance to use
            mToDoTable = mClient.getTable(UserTable.class);


        } catch (MalformedURLException e) {

        }

Button regiBtn = (Button) findViewById(R.id.signupDivertBtn);
        regiBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            try
            {
                UserTable user = new UserTable();
                user.setPassword("111");
                user.setFname("TESTName");
                user.setId("234232");
                user.setEmail("sear@tr.com");
                mToDoTable.insert(user);
            }

为什么mToDoTable.Insert()语句不起作用?将记录插入到Azure表格中不是正确的方法吗?

Why doesn't the mToDoTable.Insert() statement work? Is it not the right way to insert a record to an azure table?

这是我的UserTable实体类:

Here's my UserTable Entity class:

public class UserTable {

    @com.google.gson.annotations.SerializedName("id")
    private String id;

    @com.google.gson.annotations.SerializedName("Email")
    private String email;

    @com.google.gson.annotations.SerializedName("Password")
    private String password;

    @com.google.gson.annotations.SerializedName("UserFName")
    private String fname;


    public UserTable()
    {

    }

    public UserTable(String id, String email, String password, String fname) {
        this.setId(id);
        this.setEmail(email);
        this.setPassword(password);
        this.setFname(fname);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

推荐答案

在介绍为什么您的Android应用无法正常工作之前.我建议您确保可以先通过API帮助插入一条记录.您应该能够通过本地调试或在您发布的Azure网站上对此进行测试.一旦运行正常,您就可以通过API帮助插入一条记录.然后尝试CSharpRocks提到的内容.

Before jumping into why your Android App is not working. I suggest you making sure that you could insert a record through API help first. You should be able to either test this through local debug or on your published azure site. Once that is working correctly and you are able to insert a record through API help. Then try what CSharpRocks mentioned.

请注意,在本地调试时,应设置本地数据库(例如SQL Express服务器)并更改web.config MS_TableConnectionString以匹配.客户端应用(例如Android)中的移动客户端URL应该是调试期间在浏览器中弹出的本地URL.

Be aware that when you debug locally, you should setup a local DB like a SQL express server and change your web.config MS_TableConnectionString to match. And your mobile client URL in your client App(For example, Android) should be the local URL that pops up in the browser during debug.

这篇关于Azure移动服务:无法在表中插入任何记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆