narasiman rao

narasiman rao

  • NA
  • 519
  • 771.6k

I tried several times in combobox data is not retrieved DB

Aug 13 2015 10:39 PM
   My code as follows

In pageload i written the below code as follows

SqlConnection conn = new SqlConnection(@"Data Source=DOCTOR\SQLEXPRESS;Initial Catalog=Testing;User ID=sa;Password=a");

conn.Open();
SqlCommand sc = new SqlCommand("select Designation from Designations where active <> 'd'", conn);
SqlDataReader reader;
reader = sc.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("Designation", typeof(string));
dt.Load(reader);
dt.Load(reader);
ComboBox1.DataTextField = "Designation";
ComboBox1.DataValueField = "Designation";
ComboBox1.DataSource = dt;
ComboBox1.DataBind();
conn.Close();

In database records as follows (Table name Designations )

ID Name Designation
1 Raj Course Officer
2 Ramesh Authorised signatoury

In run mode as follows

Designation Combobox

But in combobox designation is not displayed.
i tried several time but in combobox designation is not shown.
please help me what is the problem in my above code.
  

Answers (2)