从oracle数据库向datagridview分配数据

从oracle数据库向datagridview分配数据

本文介绍了从oracle数据库向datagridview分配数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将数据从oracle数据库分配到windows应用程序中的数据网格视图但是它没有工作它没有将数据分配给数据表

请提出一些感谢提前



我的尝试:



Im trying to assign the data from the oracle data base to the data grid view in a windows application bt it is not working it is not assigning the data to data table
please suggest something thanks in advance

What I have tried:

string ConnStr = GetConnectionString_Oracle();

               // string ConnStr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
               using (OracleConnection connection = new OracleConnection())
               {
                   connection.ConnectionString = ConnStr;
                   connection.Open();
                   Console.WriteLine("State: {0}", connection.State);
                   Console.WriteLine("ConnectionString: {0}",
                                     connection.ConnectionString);

                   OracleCommand command = connection.CreateCommand();

                   string sql = "select * from LCLDocMst where LossType  ='" + lblLossType.Text.TrimStart() + "'";
                   command.CommandText = sql;

                   OracleDataReader reader = command.ExecuteReader();
                   DataTable dataTable = new DataTable();
                   dataTable.Load(reader);
                   gvDetails.DataSource = dataTable;

                   //while (reader.Read())
                   //{
                   //      myField = reader.GetInt32(0);

                   //}

               }

推荐答案

command.CommandType = CommandType.Text;

。在您的代码中的command.CommandText = sql旁边;

. next to command.CommandText=sql in your code;


这篇关于从oracle数据库向datagridview分配数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:57