从两个表中获取数据并将其放入CR [英] get data from two tables in put it in CR

查看:59
本文介绍了从两个表中获取数据并将其放入CR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个访问数据库表userdata和arear.用户数据包含uid,名字,姓氏,地址,reg_date,而arear包含uid,jan,feb,mar.
我想要的是我单击按钮,它需要当前日期,通过userdata表,并获得与当前日期/日期相同的reg_date(仅日期/日期而不是月份)的所有记录,并且它还从具有相同uid的arear表.我已经写了一些代码,但是我不明白我需要做什么

i have two access db tables userdata and arear. userdata contains uid,firstname,lastname,address,reg_date while arear contain uid,jan,feb,mar.
what i want is that i click on buton and it takes current date go through the userdata table and get all that record which has the same reg_date(only day/date not month) equal to current day/date, and it also takes data from arear table that has the same uid. i have write some code but i dont understand what i need to do

OleDbConnection connection1 = Manageconnection.Getconnection();
               string query1 = "SELECT * FROM userdata";
               OleDbCommand command = new OleDbCommand(query1, connection1);
               command.CommandType = CommandType.Text;
               OleDbDataReader reader = command.ExecuteReader();

               ArrayList data = new ArrayList();
               while (reader.Read())
               {

                   DateTime time = Convert.ToDateTime(reader[12].ToString());
                   int day = time.Day;
                   int a;
                   a = Convert.ToInt32(DateTime.Now.Day);
                   if (day == a)
                   {

                       Managedata m = new Managedata();


                       string name = reader[0].ToString();
                       string fathername = reader[1].ToString();
                       string nic = reader[2].ToString();
                       string address = reader[3].ToString();
                       string contact = reader[4].ToString();
                       string uiid = reader[6].ToString();
                       string zone = reader[7].ToString();
                       string contaction = reader[8].ToString();

                       m.full_name = name;
                       m.father_name = fathername;
                       m.nic = nic;
                       m.Address = address;
                       m.contact_no = contact;
                       m.uid = uiid;
                       m.Zone = zone;
                       m.Conection = contaction;
                       data.Add(m);

                   }


请帮帮我
在此先感谢


please help me out
thanks in advance

推荐答案

该代码似乎有误(sql部分).

如您所说,您需要用户数据以及区域数据,但我看不到您从区域中考虑的任何数据,

因此,您需要像这样更改sql
The code seems to be wrong (sql portion).

As you said, you need the user data as well as arear data, I don''t see any data you considered from arear,

So, you need to change your sql like
SELECT * FROM userdata U, arear A where U.uid=A.uid



第二件事,可以使代码更健壮,是编写sql以获取日/月.
因此,您无需在循环中添加逻辑.
这部分我留给你.

希望这会有所帮助.

欢呼



Second thing, you can make your code more robust, is to write the sql to get day/month.
So, you don''t need to add a logic in the loop.
This part I leave it to you.

Hope this helps.

cheers


这篇关于从两个表中获取数据并将其放入CR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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