轻松访问2010年的问题 [英] Easy Access 2010 question

查看:61
本文介绍了轻松访问2010年的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个非常基本的Acess数据库。  我有一个表单,我想放在组合框中,以便数据是一致的(因为我读过不使用表中的查找字段)。  但是我不知道如何将
组合框中的信息从表单链接到我的表格。  我已经尝试了几次,表中的相应框是空白的,或者其中有一个数字。  如果你能给我一些帮助,我似乎无法找到这个
修复我自己的谢谢。

I have a very basic Acess database at this point that I am building.  I have a form that I would like to put in combo boxes in so that the data is consistant (since I read not to use look up fields in a table).  However I do not know how to link the information from the combo box from the form to my table.  I have tried it a couple of times and either the coresponding box in the table is blank or there is a number in it.  If you could please give me some assistance I cant seem to find this fix on my own thank you.

推荐答案

嗨索赔,

>>如何将表格中的组合框中的信息链接到我的表格。

>>how to link the information from the combo box from the form to my table.

我做了一个简单的演示来链接它,请参考下面的代码(当我点击按钮时我会这样做,你可以将代码添加到Form_load事件中,我在运行时已经绑定了数据我的应用程序)

I make a simple demo to link it, please refer to the following code(I do it when I click the button, you can add the code to the Form_load event, I have already bound the data when I run my application)

        private void button2_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            string strCon = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\v-baf\OneDrive\MyWork\MyWinFrm\AccessDB\Database1.accdb";
            string strSql = @"select ID from Table1";
            using (OleDbConnection olCon = new OleDbConnection(strCon))
            {
                using (OleDbCommand olcmd = new OleDbCommand(strSql, olCon))
                {
                    using (OleDbDataAdapter ada = new OleDbDataAdapter(olcmd))
                    {
                        ada.Fill(ds);
                        dt = ds.Tables[0];                       
                    }
                }
            }
            comboBox1.DataSource = dt;
            comboBox1.DisplayMember = "ID";//also can display another data
        }

希望有所帮助!

最诚挚的问候,

Stanly


这篇关于轻松访问2010年的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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