我的sql数据库中有一个名为“WEB_SEL_Security_QUESTIONS”的存储过程,它返回一个表,如下所示.
SEQURITY_QUESTIONS_KEY,KEYCODE,QUESTION
我需要填充一个html选择框,其中包含我从执行上述过程中获得的问题列表.
这就是我尝试过的
String s = ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString(); sqlConnection con = new sqlConnection(s); con.open(); sqlDataAdapter myAdepter = new sqlDataAdapter("WEB_SEL_Security_QUESTIONS",con); myAdepter.SelectCommand.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); myAdepter.Fill(ds,"WEB_SEL_Security_QUESTIONS"); String questions = ds.Tables["WEB_SEL_Security_QUESTIONS"].Rows[]["QUESTION"].ToString(); securityQuestion1.DataSource = questions; securityQuestion1.DataBind();
解决方法
你可以尝试:
securityQuestion1.DataSource = ds.Tables["WEB_SEL_Security_QUESTIONS"]; securityQuestion1.DataTextField = "QUESTION"; securityQuestion1.DataValueField = "KEYCODE"; // Or whatever the value field needs to be. securityQuestion1.DataBind();
您的第一次尝试只是从一个问题中获取单个值并将其用作整个数据源.因此,您需要的目标是使整个安全问题表成为数据源,然后给出关于用于值和显示的列(DataTextField,DataValueField)的提示.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。