Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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);

                   //}

               }
Posted
Updated 23-Feb-17 6:51am
Comments
gggustafson 23-Feb-17 9:07am    
Google "c# fill datagridview from database". I would also set your gvDetails.DataSource to null before assigning dataTable to it.

1 solution

Hi,
Try to add
command.CommandType = CommandType.Text;
. next to command.CommandText=sql in your code;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900