I develop a management system at which I make a connection with C# and Oracle. It work finely. But certainly it can not work and give the following message:
Operation is not valid due to the current state of the object.
At the line:Object Price0 = dr.getString(0);
of textPIDSell_TextChanged() method.
My code segment with 'usings' and the message are included.
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;
string oraDb = "Data Source=ORCZ;User Id=ebazar;password=ebazar;";
OracleConnection Conn;
private void txtPIDSell_TextChanged(object sender, EventArgs e)
{
if (txtPIDSell.Text.Length == 5)
{
OracleDataReader dr = DynamicReader("Name,PUSP,scale","Product","Where ID = " + txtPIDSell.Text );
object price0 = dr.GetValue(0);
txtPNameSell.Text = price0.ToString();
object price1 = dr.GetValue(1);
txtPriceSell.Text = price1.ToString();
object price2 = dr.GetValue(2);
lblPerUnitSell.Text = "Per "+price2.ToString();
lblUnitSell.Text = price2.ToString();
Conn.Close();
}
}
public OracleDataReader DynamicReader(string fieldNms, string TableNms, string condition)
{
string oraDb = "Data Source=ORCZ;User Id=ebazar;password=ebazar;";
Conn = new OracleConnection(oraDb);
Conn.Open();
if (condition.Length > 0)
condition = " " + condition;
string sql = "Select " + fieldNms + " from " + TableNms + condition;
OracleCommand cmd = new OracleCommand(sql, Conn);
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
return dr;
}