Ms访问表在项目结束时丢失了数据 [英] Ms access tables lost data on project close

查看:101
本文介绍了Ms访问表在项目结束时丢失了数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个人身体

i有一个奇怪的问题我在ms访问中构建一个项目而c#i工作正常没问题一旦我工作就发现一个奇怪的事情所有数据丢失在数据中表格

i再次尝试从我的表单中添加数据以便跟踪并查找发生的情况我发现它工作正常并在我关闭项目并通过视觉或访问打开访问数据库时保存数据我发现它丢失了再次我从访问中添加数据并关闭它并再次打开它我发现数据仍然存在当我从视觉中打开项目时它会丢失最奇怪的事情只发生在一个表中并非所有表格使用此表格代码的表格是< br $>


hi every body
i have a strange problem i build a project in ms access and c# i was working fine no problem once i work on it i discover a strange thing all data is lost on data in the table
i try to add data from my form again to follow and find what happen i find that it works fine and save data when i close the project and open access database through visual or access i find its lost again i add data from access and close it and open it again i find data is still there when i open the project from visual it get lost the most strange that happen for only one table not all tables the form which use this table code is

private void btnsave_Click(object sender, EventArgs e)
{

    try
    {
        _con = new OleDbConnection(_cs);
        _con.Open();
        string newVariable =
           string.Format(@"SELECT  top 1 Tbl_UserDetails.Installment_Number FROM Tbl_Users INNER JOIN Tbl_UserDetails ON Tbl_Users.USer_ID = Tbl_UserDetails.USer_ID  WHERE Tbl_Users.Name='{0}' ORDER BY Tbl_UserDetails.Installment_date DESC", txtname.Text);
        _cmd = new OleDbCommand(newVariable, _con);_ds = new DataSet();
        _da = new OleDbDataAdapter(_cmd);_da.Fill(_ds, "Tbl_InstallmentCount");
        if (_ds.Tables[0].Rows.Count != 0)
        {_installNumber = Convert.ToInt32(_ds.Tables[0].Rows[0]["Installment_Number"]);
        }

        if (_installNumber == 0)
        {
            _installNumber = 1;
        }else
        {
            _installNumber += 1;
        }
        string cb =
            string.Format(@"insert into Tbl_UserDetails( USer_ID, Installment_Number, Installment_previous_Rest,Installment_Change,Installment_Total, Installment_date) VALUES ({0},{1},{2},{3},{4},{5})",
                _x, _installNumber, txttotal.Text, txtpay.Text, txtsumtotal.Text, string.Format("#{0}#", dateTimePicker1.Value.ToShortDateString()));

        _cmd = new OleDbCommand(cb) {Connection = _con};
        _cmd.ExecuteReader();
        _con.Close();
        XtraMessageBox.Show(@"added", "add", MessageBoxButtons.OK,
            MessageBoxIcon.Information);
        Clear();


        if (_installNumber != 0)
        {_installNumber = 0;
        }

        gridControl1.DataSource = null;
    }
    catch (Exception ex)
    {
        XtraMessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}







问题在哪里(我的代码 - 办公室 - 窗口或什么?)




where is the problem (My code - office - windows or what ??)

推荐答案

您的数据丢失,因为每次在Visual Studio中运行项目时,数据库都是从该项目退回到bin文件夹,覆盖您在以前的运行中所做的任何更改。当您每次运行项目时将数据库添加到项目中时,您正在将数据库恢复到其启动状态。
Your data is being lost because every time you run the project in Visual Studio, the database is being copied from the project back down to the bin folder, OVERWRITING ANY CHANGES YOU MADE IN THE PREVIOUS RUN. You're are restoring the database to its starting state when you added it to the project every time you run your project.


这篇关于Ms访问表在项目结束时丢失了数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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