0

我創建了一個azure移動服務並正確設置了所有數據庫表(測試它們)。但是,當我嘗試通過我的Android應用程序向我的SQL表中插入記錄時,記錄不會被添加。 (是的,我的SQL表也準備好了移動服務,也改變了模式)Azure移動服務:無法向表中插入任何記錄?

我也沒有收到錯誤。

這裏是我的代碼:

@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("[email protected]"); 
       mToDoTable.insert(user); 
      } 

爲什麼沒有mToDoTable.Insert()語句的工作?將記錄插入天藍色表格不正確嗎?

編輯:

這裏是我的用戶表的實體類:

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; 
    } 
} 

回答

0

在跳入爲什麼你的Android應用程序不工作之前。我建議你確保你可以先通過API幫助插入一條記錄。您應該能夠通過本地調試或在已發佈的天青網站上進行測試。一旦工作正常,並且您可以通過API幫助插入記錄。然後嘗試一下CSharpRocks提到的內容。

請注意,當您在本地進行調試時,應該像設置SQL Express服務器一樣設置本地數據庫,並將您的web.config MS_TableConnectionString更改爲匹配。並且您的客戶端應用程序(例如,Android)中的移動客戶端URL應該是在調試期間在瀏覽器中彈出的本地URL。

0

你mobileServiceUrl值是錯誤的。它應指向您的移動服務的根源,如「https://YOURSERVICENAME.azure-mobile.net/」。

我會讓服務爲您設置ID(GUID)。如果你不喜歡它,只需添加另一個字段來存儲你自己的ID。

+0

嗯我試過這種URL格式,但仍然沒有運氣。我的插入代碼是否正確? – user3306938

+0

您是否更改了插入操作的權限? – CSharpRocks

+0

不,我沒有。請解釋親愛的先生:) – user3306938

相關問題