Click here to Skip to main content
15,890,512 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: C#.Net Windows Application Pin
MaulikDusara26-May-13 18:30
MaulikDusara26-May-13 18:30 
GeneralRe: C#.Net Windows Application Pin
Mohsin Afzal27-May-13 3:45
professionalMohsin Afzal27-May-13 3:45 
Questionmvc book Pin
Member 870181318-May-13 1:13
Member 870181318-May-13 1:13 
AnswerRe: mvc book Pin
cyber_addicted21-May-13 0:38
cyber_addicted21-May-13 0:38 
GeneralRe: mvc book Pin
Member 870181321-May-13 3:40
Member 870181321-May-13 3:40 
GeneralRe: mvc book Pin
cyber_addicted21-May-13 20:15
cyber_addicted21-May-13 20:15 
QuestionAccess Database, ASP/C# Drop Down List populating a Drop Down List Pin
WickedFooker17-May-13 15:00
WickedFooker17-May-13 15:00 
AnswerRe: Access Database, ASP/C# Drop Down List populating a Drop Down List Pin
Richard Deeming20-May-13 2:02
mveRichard Deeming20-May-13 2:02 
WickedFooker wrote:
strSQL = "select * from tblEmployee where canTeach=" + Teachable;

Your first problem is SQL Injection[^]. Never use string concatenation to insert parameters into a query; use a parameterized query instead.

WickedFooker wrote:
dbCmd = new OleDbCommand(strSQL, dbConn);
DataSet ds = new DataSet();
dbConn.Close();

Creating an OleDbCommand object isn't going to execute the query, let alone store the results in another variable. You could use ExecuteReader, iterate through the results, and add them to a DataTable, but it's much simpler to use a DataAdapter to do the work for you.


WickedFooker wrote:
if (ddlTeacher.SelectedValue == "0")
{
   ddlTeacher.Items.Clear();
   ddlTeacher.Items.Insert(0, new ListItem("--Select--", "0"));
}

Since you've just inserted an item with a value of "0" as the first item, this will most likely be the selected item. Even if your data-binding was working, this block of code will most likely throw away the results from the database and leave you with an empty list.


Try something like this:
C#
protected void ddlcourseType_SelectedIndexChanged(object sender, EventArgs e)
{
   string path = Server.MapPath("eAcademy_DB.mdb");
   string connectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + path;
   string commandText = "SELECT * FROM tblEmployee WHERE canTeach = ?";

   var ds = new DataSet();

   using (var connection = new OleDbConnection(connectionString))
   using (var command = new OleDbCommand(commandText, connection))
   {
      // OleDbCommand uses positional, rather than named, parameters.
      // The parameter name doesn't matter; only the position.
      command.Parameters.AddWithValue("@p0", ddlcourseType.SelectedValue);

      var adapter = new OleDbDataAdapter(command);
      adapter.Fill(ds);
   }

   ddlTeacher.DataSource = ds;
   ddlTeacher.DataTextField = "emp_ID";
   ddlTeacher.DataValueField = "emp_ID";
   ddlTeacher.DataBind();

   ddlTeacher.Items.Insert(0, new ListItem("--Select--", "0"));
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Access Database, ASP/C# Drop Down List populating a Drop Down List Pin
WickedFooker20-May-13 5:34
WickedFooker20-May-13 5:34 
AnswerRe: Access Database, ASP/C# Drop Down List populating a Drop Down List Pin
cyber_addicted21-May-13 0:53
cyber_addicted21-May-13 0:53 
Questionhow to write sql's not in operator using linq to entities 4.0 Pin
indian14317-May-13 7:14
indian14317-May-13 7:14 
AnswerRe: how to write sql's not in operator using linq to entities 4.0 Pin
R. Giskard Reventlov20-May-13 6:11
R. Giskard Reventlov20-May-13 6:11 
QuestionEF:How to link Expressions in order to generate an OR/AND Linq query Pin
Clodetta del Mar17-May-13 1:44
Clodetta del Mar17-May-13 1:44 
Answer[solved?]the concrete calling...the priority problem Pin
Clodetta del Mar17-May-13 2:51
Clodetta del Mar17-May-13 2:51 
QuestionHow to use different fonts? Pin
Jassim Rahma16-May-13 10:15
Jassim Rahma16-May-13 10:15 
AnswerRe: How to use different fonts? Pin
Richard MacCutchan16-May-13 21:20
mveRichard MacCutchan16-May-13 21:20 
AnswerRe: How to use different fonts? Pin
Jitendra Parida - Jeetu20-May-13 1:02
Jitendra Parida - Jeetu20-May-13 1:02 
AnswerRe: How to use different fonts? Pin
wikizhao27-May-13 21:18
wikizhao27-May-13 21:18 
QuestionHow to Open Datalist Link Button in New Tab in browser Pin
Member 998801815-May-13 21:35
Member 998801815-May-13 21:35 
AnswerRe: How to Open Datalist Link Button in New Tab in browser Pin
Richard Deeming16-May-13 1:32
mveRichard Deeming16-May-13 1:32 
Questionc# code to download .xlsm file Pin
Sachin Adsul15-May-13 21:20
Sachin Adsul15-May-13 21:20 
AnswerRe: c# code to download .xlsm file Pin
ZurdoDev21-May-13 10:26
professionalZurdoDev21-May-13 10:26 
QuestionPlease Help With Various Methods of Optical Character Recognition which can be used for successful Conversion?? Pin
Kaushal Behere15-May-13 20:52
professionalKaushal Behere15-May-13 20:52 
QuestionHtml to PDF Pin
Denzil_Sdn15-May-13 19:56
Denzil_Sdn15-May-13 19:56 
AnswerRe: Html to PDF Pin
Mohammed Hameed18-May-13 10:59
professionalMohammed Hameed18-May-13 10:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.