0
public partial class Form : System.Web.UI.Page
{
    private void connecttodb()
    {
        OracleConnection conn = new OracleConnection();
        conn.ConnectionString = "User Id=WLL; Password=wll; Data Source=WLL;";
     }
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            String CommandText = "Select DepartmentID,Department from its_department;";
            OracleDataReader odr = GetDr(CommandText, ConnectionString);
            DropDownList1.DataSource = odr;
            DropDownList1.DataTextField ="Department";
            DropDownList1.DataValueField ="DepartmentID";
            DropDownList1.DataBind();
        }
   private OracleDataReader GetDr(String sqltext, String ConnectionString)
            {
              OracleDataReader dr;
              OracleConnection oracle_conn = new OracleConnection(ConnectionString);
              OracleCommand Oracle_cmd = new OracleCommand( sqltext, conn );
               Oracle_cmd.Connection.open();
              dr = Oracle_cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
              return dr;
            }
   
}

Edited by peter_budo: Please do not use CODE SNIPPET option to post question. Use FORUM THREAD instead. When posting code use code tags

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Lusiphur
1
public partial class Form : System.Web.UI.Page
{
    private void connecttodb()
    {
        OracleConnection conn = new OracleConnection();
        conn.ConnectionString = "User Id=WLL; Password=wll; Data Source=WLL;";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            String CommandText = "Select DepartmentID,Department from its_department;";
            OracleDataReader odr = GetDr(CommandText, ConnectionString);
            DropDownList1.DataSource = odr;
            DropDownList1.DataTextField ="Department";
            DropDownList1.DataValueField ="DepartmentID";
            DropDownList1.DataBind();
        }
    }
    private OracleDataReader GetDr(String sqltext, String ConnectionString)
    {
        OracleDataReader dr;
        OracleConnection oracle_conn = new OracleConnection(ConnectionString);
        OracleCommand Oracle_cmd = new OracleCommand( sqltext, conn );
        Oracle_cmd.Connection.open();
        dr = Oracle_cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
        return dr;
    }
}

Issue was with brace ending Page_Load. General rule of thumb that I work with is to always ensure that when I open a brace I immediately close it and then start filling betwen the braces with my statements. This way I never forget to close a brace. Also, not sure if the posted code reflects your actual code but ensuring that tab stops are enforced (4 spaces per indent level) uniformly throughout your code makes it easier to spot and correct things like that.

Hope this helps :) Please remember to mark the thread solved once your issue is resolved.

Edit:

u have missed brace for partial class form

Incorrect but s'all good...

Add a braces before "private OracleDataReader GetDr(String sqltext, String ConnectionString)"

This was correct :twisted:

Edited by Lusiphur: n/a

Votes + Comments
well written and spot on
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.