问题描述
SqlConnectioncon=DB.createConnection();con.Open();SqlCommandcmd=newSqlCommand("select*fromtype",con);SqlDataReadersdr=cmd.ExecuteReader();this.DropDownList1.DataTextField="typeName";this.DropDownList1.DataValueField="typeID";this.DropDownList1.DataSource=sdr;this.DropDownList1.DataBind();sdr.Close();con.Close();这是用DropDownList读取数据,现在我想写入数据库,取DropDownList的ID应该怎样取下在是写入数据库privatevoidButton1_Click(objectsender,System.EventArgse){SqlConnectioncon=DB.createConnection();con.Open();SqlCommandaddcommand=newSqlCommand("insertintotitlevalues('"+this.txttitle.Text+"','"+this.DropDownList1.SelectedValue+"','"+this.txtnr.Text.Replace("n","<br>").Trim().Replace("",">").Trim()+"','"+System.DateTime.Now.ToString()+"')",con);addcommand.ExecuteNonQuery();con.Close();Response.Write("<script>alert('发表成功!');</script>");txttitle.Text="";txtnr.Text="";}我是用"+this.DropDownList1.SelectedValue+"但不成功.望高手指点
解决方案
解决方案二:
应该不是DropDownList1的事,建议你把插入语句 输出来 测试一下