2012-11-13 75 views
2

我用sql數據庫製作了一個C#程序。我使用從數據源中拖放來創建表單。但是當我按下保存按鈕時,數據不會保存在數據庫中。BindingNavigator保存按鈕不會將數據保存到數據庫中

enter image description here

自動生成的代碼是

namespace test3 
{ 
public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
    } 

    private void tableTest3BindingNavigatorSaveItem_Click(object sender, EventArgs e) 
    { 
     Validate(); 
     this.tableTest3BindingSource.EndEdit(); 
     this.tableAdapterManager.UpdateAll(this.test3DataSet); 
     //this.tableTest3TableAdapter.Update(this.test3DataSet.TableTest3); // I tried to add this line but it also not work !! 

    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     // TODO: This line of code loads data into the 'test3DataSet.TableTest3' table. You can move, or remove it, as needed. 
     this.tableTest3TableAdapter.Fill(this.test3DataSet.TableTest3); 

    } 
} 
} 

我一定要添加一些代碼或更改屬性,當我創建了以下在網站上的步驟數據庫的方式,它必須是正確的。

回答

4

默認情況下,在解決方案資源管理器中,數據庫設置爲始終複製到bin \ debug文件夾,這意味着數據庫被應用程序文件夾中的一個覆蓋。

解決方案: 您可以將此屬性更改爲「不復制」,並在需要時將其自行復制或將數據庫從項目中移出。當被要求在創建連接時將其帶入項目中時,sympy說不。或者您應該將連接字符串目錄更改爲項目forlder中的數據庫,而不是在調試文件夾中。這應該工作。