-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;
            }
   
}

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Lusiphur
0

The only mistak is you are not passing connection string to your finction
i.e. GetDr(String sqltext, String ConnectionString). the only the command is passing at this function but connection string is not initialise that's why it gives error.
for recovery create one public string for connection string
string cons="User Id=WLL; Password=wll; Data Source=WLL;";

and then pass this string whenever you call function
GetDr(Commandtext,cons)
try it. if you got your answer mark thread as solved.

Edited by pritesh2010: n/a

1

Only thing I'm going to say here is... when did DaniWeb become the equivalent of a compiler's built-in syntax and error checker?

If you have a specific problem with the code or it's not working in an expected way it would be appreciated if you would provide the error details for the community here to work with instead of plastering a chunk of code (without the code formatting braces) into the page with the title "check the code for errors".

Votes + Comments
Agreed.
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.