MS访问如何用C#中的多个表填充数据集 [英] MS access how to fill dataset with multiple tables in C#

查看:74
本文介绍了MS访问如何用C#中的多个表填充数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string connString = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString;

            string cmdString = "SELECT * FROM tblBasicInfo, tblAccData WHERE ID =" + Convert.ToInt32(AcNotextBox.Text);

            //string query = "SELECT * FROM tblAccData WHERE ID =" + Convert.ToInt32(AcNotextBox.Text);


            using (OleDbConnection conn = new OleDbConnection(connString))
            {
                using (OleDbCommand cmd = new OleDbCommand(cmdString, conn))


                {
                    conn.Open();

                    OleDbDataReader reader = cmd.ExecuteReader();
                    

                    if (reader.Read())
                    {
                        StudentNametextBox.Text = (reader["SName"].ToString());
                        FatherNametextBox.Text = (reader["FName"].ToString());
                        ClasscomboBox.Text = (reader["ClassofReading"].ToString());
                        TransportFatextBox.Text = (reader["TranFacility"].ToString());
                        RemarkstextBox.Text = (reader["Remarks"].ToString());
                        CelltextBox.Text = (reader["Cell"].ToString());
                        TrantextBox.Text = (reader["TransportChr"].ToString());
                        
                        DuestextBox.Text = (reader["Dues"].ToString());
                        AdmfeetextBox.Text = (reader["Adm"].ToString());
                        ProFeetextBox.Text = (reader["Pro"].ToString());





我有什么试过:





What I have tried:

MS Access how to fill dataset with multiple tables in c#





请帮我从文本框中的访问多表中设置数据我从1表单调用数据访问



please help me ho set data from access multi table in textbox i have calling data for access from 1 form

推荐答案

首先,永远不要使用连接字符串作为查询。这会让您了解 Sql Injection [ ^ ]。而不是这个,使用参数化查询 [ ^ ]。



一个合适的处理数据的方法是创建数据访问层 [ ^ ]和Bussines Logic Layer [ ^ ]。



最后,我强烈建议您阅读:撰写便携式数据访问层 [ ^ ]并且:通过ADO.NET接口进行简化数据库访问 [ ^ ]
First of all, NEVER use concatenating string as a query. This exposes you on Sql Injection[^]. Rather than this, use parameterized queries[^].

A proper way to work with data is to create Data Access Layer[^] and Bussines Logic Layer[^].

Finally, i'd strongly recommend to read this: Writing a Portable Data Access Layer[^] and this: Simplified Database Access via ADO.NET Interfaces[^]


这篇关于MS访问如何用C#中的多个表填充数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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