在组合框中,数据不会从Web应用程序中的数据库中恢复 [英] in combobox data is not retrived from the database in web application

查看:46
本文介绍了在组合框中,数据不会从Web应用程序中的数据库中恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下



SqlConnection conn = new SqlConnection(Data Source = DOCTOR\SQLEXPRESS; Initial Catalog = HIMT_Testing; User ID = sa; Password = himt123);



conn.Open();



SqlCommand sc = new SqlCommand(select从名称中指定激活<>'d',conn);



SqlDataReader阅读器;

reader = sc.ExecuteReader( );

DataTable dt = new DataTable();

dt.Columns.Add(Designation,typeof(string));

dt.Load(读者);



ComboBox1.DataTextField =指定;

ComboBox1.DataValueField =指定;



ComboBox1.DataSource = dt;

conn.Close();



in没有从数据库中检索组合框数据。



我的代码中有什么问题。它是web应用程序。

解决方案

ComboBox1.DataSource = dt;

在此行之后你应该写

ComboBox1.DataBind();

my code as follows

SqlConnection conn = new SqlConnection("Data Source=DOCTOR\SQLEXPRESS;Initial Catalog=HIMT_Testing;User ID=sa;Password=himt123");

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

ComboBox1.DataTextField = "Designation";
ComboBox1.DataValueField = "Designation";

ComboBox1.DataSource = dt;
conn.Close();

in combo box data is not retrieved from the database.

what is the problem in my code. it is web application.

解决方案

ComboBox1.DataSource = dt;
After this line you should write
ComboBox1.DataBind();


这篇关于在组合框中,数据不会从Web应用程序中的数据库中恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆