保存数据C#Winform后库存表格不更新自身 [英] Inventry Form Not Updating itself after Save data C# Winform

查看:28
本文介绍了保存数据C#Winform后库存表格不更新自身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括屏幕截图但堆栈溢出不允许我这样做.希望我以这种方式向您清楚.在我的应用程序中,如果用户名已存在于 SQLite 数据库中,我想自动填充剩余的文本框.就像下面的代码

I want to include screen shots but stack overflow not letting me to do that.Hope I am clear to you in this way.In my application I want to autofill remaining text boxes if user name is already present in the SQLite database.Like in below code

 private void cname_txt_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Enter)
        {
            SQLiteConnection sqliteCon = new SQLiteConnection(dbConnectionString);
            // open connection to database 
            try
            {
                sqliteCon.Open();
                string Query = "select * from OwnerDetails where Name='" + cname_txt.Text + "' ";
                SQLiteCommand createCommand = new SQLiteCommand(Query, sqliteCon);
                SQLiteDataReader dr = createCommand.ExecuteReader();
                while (dr.Read())
                {
                    string Name = dr.GetString(0);
                    string Agency = dr.GetString(1);
                    string CellNo = dr.GetString(2);
                    string Office = dr.GetString(3);
                    string Email = dr.GetString(4);
                    string Address = dr.GetString(5);
                    cname_txt.Text = Name;
                    cagency_txt.Text = Agency;
                    ccellno_txt.Text = CellNo;
                    coffice_txt.Text = Office;
                    cemail_txt.Text = Email;
                    caddress_txt.Text = Address;

               }
                sqliteCon.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

但是我的应用程序没有根据数据库最近的值更新自己.我需要关闭应用程序然后重新打开它.然后它将在自动完成名称文本框中显示数据.我试过了

But my Application not updating itself from database recent values. I need to close application and then reopen it . Then it will show data in the autocomplete Name textbox. I have tried

this.refresh();
this.dispose();
this.hide();

几乎所有到主应用程序,但主应用程序没有刷新到新的数据库值我知道我需要在保存按钮代码中添加任何更新查询,但我无法这样做.您的帮助将不胜感激

almost all to main application but main application is not refreshing to new database values I know I need to put any update query in the save button code but I am unable to do that. Your help will be appreciated

推荐答案

代码看起来不错(我没有要测试的 sqlite).你确定,那行

The code looks ok (i don't have sqlite to test). Are you sure, that the line

cname_txt.Text = Name;

真的达到了吗?可能在数据库中什么都没有找到.

really is reached? May be nothing is found in the database.

这篇关于保存数据C#Winform后库存表格不更新自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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