General discussion

Locked

ASP.Net Databind in DropDownList

By bsmgopal1984 ·
I tried to display the values from oracle table into a dropdownlist which is in asp.net.I used the below code to bind the data.When I debug,the page loads completely.But it doesn't show anything in the dropdownlist.How can I get the Oracle table values in asp.net dropdownlist.
I used the below code:

private void Page_Load(object sender, System.EventArgs e)
{
InitializeComponent();
ConnStr="Provider=msdaora;Data Source=inchnred;User Id=inchnset;Password=inchn;";
Conn=new OleDbConnection(ConnStr);
Conn.Open();
DataAdpt=new OleDbDataAdapter("SELECT * FROM TBLTEST",Conn);
DataAdpt.SelectCommand.CommandType=CommandType.Text;
DataSet ds=new System.Data.DataSet("TBLTEST");
DataAdpt.Fill(ds,"tbltest");
DropDownList1=new DropDownList();
DropDownList1.DataSource=ds.Tables[0];
DropDownList1.DataTextField="Name";
DropDownList1.DataValueField="EMP";
DropDownList1.DataBind();
}

*Table name is TBLTEST
*It has columns Name,EMP

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by NZBN In reply to ASP.Net Databind in Drop ...

If it works in debug mode but not when you run it it must be something to do with how your code finds the database. Maybe ODBC not setup properly - if the page loads fine its not an ASP problem its your SQL Connection string. Try the www.asp.net forum dedicated to oracle connections.
Also try using the gui wizard to connect you to the database - ie drag and drop using the RAD tool menu and follow the wizard (must be in gui not code mode) when you do this. Then go to the code and see what you get and compare the two.

Collapse -

by bsmgopal1984 In reply to

Poster rated this answer.

Collapse -

by vrvaperanki In reply to ASP.Net Databind in Drop ...

I had the same problem while I was trying to connect in VB.Net. I tried to change the provider and I got it. U can try it also. Type provider=oraoledb.oracle
This should work. Also check data source, UserID and password for correct spelling

Collapse -

by bsmgopal1984 In reply to

Poster rated this answer.
Thanks for your ideas.
Now I got clearly....
I used the below code:

if(!IsPostBack)
{
ConnStr="Provider=msdaora;Data Source=inchnset;User Id=inchnasset;Password=inchnqw;";
Conn=new OleDbConnection(ConnStr);
cmd=new OleDbCommand("select deptmgr,deptno from tblmgr",Conn);
Conn.Open();
Dropdownlist3.DataSource=cmd.ExecuteReader();
Dropdownlist3.DataTextField="DEPTMGR";
Dropdownlist3.DataValueField="DEPTNO";
Dropdownlist3.DataBind();
Conn.Close();
}

Collapse -

by henry888chin In reply to ASP.Net Databind in Drop ...

If you haven't created the "tbltest" table in the "dsTest" dataset, you'll need to create one. However, "tbltest" needs to be defined to have the fields as in the actual TBLTEST and/or other tables in the database. It seems that ADO.NET does not know how to put the retrieved table data in the current "TBLTEST" dataset.

The way I'd do is to define the "tbltest" table similar to the same table or a set of tables in the database for the fields that I need to work with. For example, I'll create a "tblPay" within a "dsPayroll". "tblPay" will contain only fields that I need to work with. When selecting fields from the actual database, do a "select a.ssn, a.last_name, a.first_name, b.pay_rate, c.days_worked from Personnel a, PayRate b, Timecard c". Once you have the "tblPay" defined, the retrieved data will know where to go in the memory database. Hopefully, this will help to point you in the right direction. Regards, HC.

Collapse -

by bsmgopal1984 In reply to

Poster rated this answer.

Collapse -

by bsmgopal1984 In reply to ASP.Net Databind in Drop ...

This question was closed by the author

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums