本文介绍了N在Asp Web中使用下拉控件从此代码工作正常但是当我在Asp Winform中使用此代码时它给我错误我能做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void populatesocietyname()

{

string CS = ConfigurationManager.ConnectionStrings [SocietyCS] .ConnectionString;

使用(SqlConnection con = new SqlConnection(CS))

{

SqlCommand cmd = new SqlCommand(select SocietyID,SocietyFullName from tblsociety,con);

con.Open();

SqlDataReader rdr = cmd.ExecuteReader();

ddlsocietyname.DataTextField =SocietyFullName;

ddlsocietyname.DataValueField =SocietyID;

ddlsocietyname.DataSource = grdr;

ddlsocietyname.DataBind();

ddlsocietyname .Items.Insert(0,n

ew ListItem( - 选择社会名称 - ,0));

}

}



这个win形式的代码给出错误我试图cha nge datatext to valued显示一个datavaluefield到valuisplay但它在datasource给出错误我怎么解决这个?

解决方案

private void populatesocietyname()
{
string CS = ConfigurationManager.ConnectionStrings["SocietyCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("Select SocietyID,SocietyFullName from tblsociety", con);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
ddlsocietyname.DataTextField = "SocietyFullName";
ddlsocietyname.DataValueField = "SocietyID";
ddlsocietyname.DataSource = grdr;
ddlsocietyname.DataBind();
ddlsocietyname.Items.Insert(0, n
ew ListItem("-- Select Society Name --", "0"));
}
}

This code in win form give error i tried to change the datatext to valuedisplay a datavaluefield to valuedisplay but it give error at datasource how i can solve this?

解决方案


这篇关于N在Asp Web中使用下拉控件从此代码工作正常但是当我在Asp Winform中使用此代码时它给我错误我能做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 12:06