链接表以我们的数据输入形式(窗口形式) [英] Link table in our data entry form(window form)

查看:99
本文介绍了链接表以我们的数据输入形式(窗口形式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以数据输入形式(窗口形式)链接表.以可视化studeo 2008在窗口形式上创建数据输入形式,并在ms access 2007中创建表

How to link table in data entry form (window form).Data entry form create on window form in visual studeo 2008 and table create in ms access 2007

推荐答案

您想从数据库中检索数据并将其输出到Windows窗体控件或什么?..如果那是您要执行的操作,则必须执行以下操作..

1.首先在Access数据库(2003/2007)中创建表.

2.现在,您可以使用以下代码获取所需的数据
You want to retrieve data from a database and output it unto a windows form control or what?..If thats what you want to do then you''d have to do the following..

1. first create your table in an Access database (either 2003/2007).

2. Now you can use the following code to get the data you need
//Add the following namespaces to the calling class
using System.Data;
using System.Data.OLEdb;
using System.Windows.Forms;
..

class DB
{

public void getData([form controls here as parameters eg.] Textbox tbxFname, Textbox tbxLname)
{
   OLEdbConnection conn=new OLEdbConnection();
   conn.ConnectionString="Provider=Microsoft.JET.4.0; Data Source=[database name here].mdb(if access 2003)/.accdb(if access 2007)";

   
   OLEdbCommand cmd=new OLEdbCommand();
   cmd.Connection=conn;
   cmd.CommandType=CommandType.Text;
   cmd.CommandText="select * from [table name here] where [specify condition here]";

   OLEdbDataReader rd;
   rd=cmd.ExecuteReader();

   while(rd.Read())
   {
     tbxFname.Text=(rd[0].Value).toString();
     tbxLname.Text=(rd[1].Value).toString();
     .....
     // other controls will be linked to various reader values and also the numbers o,1 etc signify the field position in the database


   }
conn.Close();
cmd.Dispose();


}
}



要调用表单上的代码,
1.首先在form_load事件中为类创建一个对象,例如:



To call the code on the form,
1. First create an object to the class in the form_load event, Example :

DB _object = new DB();
_object.getData([input argument list here]);

// but make sure arguments reference the form controls



而且,当您构建项目时,我认为在进行正确的更改后它应该可以工作!



And when you build the Project I think it should work after you make the right changes!


这篇关于链接表以我们的数据输入形式(窗口形式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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