我想读出数据库中的字段,放入dropdownlist中,可为什么显示错误说:未将对象引用设置到对象的实例。这是怎么回事啊?我是这么写的 SqlConnection conn5 = new SqlConnection();
conn5.ConnectionString = "server=localhost;database=DZSW;uid=ziye;password=123";
conn5.Open();
SqlCommand cmd5 = new SqlCommand("select * from tb_goods where ID='" + Request.QueryString["ID"].ToString() + "'", conn5);
SqlDataReader sdr5 = cmd5.ExecuteReader();
sdr5.Read();
this.DropDownList1.SelectedItem.Text = sdr5["typeName"].ToString();数据库中肯定是有typeName这个字段的,不过我页面上有两个DropDownList,用来实现连动功能的,是不是做了联动功能我就不能给第二个DropDownList赋值了啊?
conn5.ConnectionString = "server=localhost;database=DZSW;uid=ziye;password=123";
conn5.Open();
SqlCommand cmd5 = new SqlCommand("select * from tb_goods where ID='" + Request.QueryString["ID"].ToString() + "'", conn5);
SqlDataReader sdr5 = cmd5.ExecuteReader();
sdr5.Read();
this.DropDownList1.SelectedItem.Text = sdr5["typeName"].ToString();数据库中肯定是有typeName这个字段的,不过我页面上有两个DropDownList,用来实现连动功能的,是不是做了联动功能我就不能给第二个DropDownList赋值了啊?
解决方案 »
- 如何获取GridView中RadioButtonList中RadioButton的选中状态?
- 跪求大虾。干掉它,您就是我的神。。。
- 主页面优化问题
- 再出一帖 gridview中怎么增加一个 “排名” 列
- 急请教:调试asp.net程序的时候,不能关闭起始页,否则就无法调试
- Repeater分页打印如何实现?
- 2010版最新"Dom文档对象模型手册"提供下载,web开发者必备
- 有关存储过程在C#中调用返回值的问题
- 不知道大家在验证码中的干扰点是怎么做的,我一点思路都没有
- Web Service性能测试,欢迎评论,来者有分!
- Ajax-toolkit和Atlas区别?
- asp.net C#数据据问题
SqlCommand cmd5 = new SqlCommand("select * from tb_goods where ID=" + Request.QueryString["ID"].ToString() , conn5);
1.Request.QueryString["ID"] 为null2.SqlDataReader 读完后就要关闭
conn5.ConnectionString = "server=localhost;database=DZSW;uid=ziye;password=123";
conn5.Open(); SqlCommand cmd5 = new SqlCommand("select * from tb_goods where ID=" + Request.QueryString["ID"].ToString() + "", conn5); SqlDataReader sdr5 = cmd5.ExecuteReader();
sdr5.Read();
this.DropDownList1.SelectedValue = sdr5["typeName"].ToString();别的值都能取到的``可是就是DropDownList1里面没值`这是为什么啊?
你Response.Write(sdr5["typeName"].ToString())有没有值?
依據上面的話,是不是應該是DropDownList2啊
给DropDownList这么赋值对的吧``应该?
我第一个DropDownList ID是DDD,第二个DropDownList ID是DropDownList1现在就是为什么``值能取出来的``就是赋值不上去``很郁闷``
这样试试DropDownList1.Items.Add(new ListItem(sdr5["typeName"].ToString(),sdr5["typeName"].ToString()));