Click here to Skip to main content
15,886,632 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to access data from database table at the selected index change of dropdownlist & show on to the existing label for which

I write a code as follow where ddlweek7 is Dropdownlist & initials starting from lbl are the labels

C#
protected void DDLWEEK7_SelectedIndexChanged(object sender, EventArgs e)
    {

OleDbConnection con = new OleDbConnection("Provider=MSDAORA;User ID=sd;password=s321;Data Source=User");
    
 OleDbCommand cmd3 = new OleDbCommand("SELECT d1  FROM VIPUL_DATE WHERE dw=@p1"+DDLWEEK7.SelectedItem, con);
    
 con.Open();
     
OleDbParameter op = new OleDbParameter();
     op.ParameterName = "@p1";
     op.Value = DDLWEEK7.SelectedItem.ToString();
     cmd3.Parameters.Add(op);

OleDbDataReader DR1= cmd3.ExecuteReader();

       
lblfrmdt.Text+=DR1.ToString();

}

for this i got the error as [One or more errors occurred during processing of command.ORA-00936: missing expression]
Posted
Updated 27-Jul-11 19:53pm
v2

Not sure why you are concatenating a value on your query while you have specified a parameter on it. Try replacing the code of your OleDbCommand to this.
C#
OleDbCommand cmd3 = new OleDbCommand("SELECT d1  FROM VIPUL_DATE WHERE dw=@p1", con);

Also, this (op.Value = DDLWEEK7.SelectedItem.ToString();) will only return the type of the selected item, which is ListItem, and not the value. Im not sure about your purpose of using this. Try using DDLWEEK7.SelectedValue instead. Or if you want the index of the selected item, use DDLWEEK7.SelectedIndex property. Refer here[^] for more details about the DropDownList class.
 
Share this answer
 
v2
Hi,

Your code is not clear...
What is you objectives?
Maybe you want to retrieve one record in oracle table.
Right?... If so...
See this example:

In you Web.config:
   <connectionStrings>
  <add name="ORAConnection" connectionString="Provider=MSDAORA;Data Source=User;User ID=sa;Password=s321"/>
</connectionStrings>


In your code behind:

string OraConn = ConfigurationManager.ConnectionStrings["ORAConnection"].ConnectionString;  
   //string retVal = string.empty;   
   OleDbConnection oconn;
   OleDbCommand ocmd;
   OleDbDataReader odr;
   try
   {
       using (oconn = new OleDbConnection(OraConn))
       {
           oconn.Open();
           string query = "SELECT d1 FROM VIPUL_DATE WHERE dw ='" + UserId + "'";
           using (ocmd = new OleDbCommand(query, oconn))
           {
               OleDbDataReader odr = ocmd.ExecuteReader();
               if (odr.Read())
               {
                  retVal = odr["d1"].ToString();  // U should handle this if null...
               }
           }
      }
   }
   
   catch(Exception ex)
   {
        throw ex;
   }
   lblfrmdt.Text = retVal;


Regards,

Algem
 
Share this answer
 
v2

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