protected void DetailsView2_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
GridViewMove.DataBind();
DropDownList myDDNewUnit = DetailsView2.FindControl("DDNewUnit") as DropDownList;
string connectionString = ConfigurationManager.ConnectionStrings["MyDB"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
String StrQ = "select unitid from unit where 单位名称='" + myDDNewUnit.SelectedValue.ToString() + "'";
SqlCommand myCommand = new SqlCommand(StrQ, myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();
myReader.Read();
string NewUnit;
NewUnit = myReader[0].ToString();
myReader.Close(); DropDownList myDDNewDepartment = DetailsView2.FindControl("DDNewDepartment") as DropDownList;
String StrQDepartmentId = "select departmentid from department where 部门名称='" + myDDNewDepartment.SelectedValue.ToString() + "' and unitid=" + NewUnit;
SqlCommand myCommand1 = new SqlCommand(StrQDepartmentId, myConnection);
SqlDataReader myReader1 = myCommand1.ExecuteReader();
myReader1.Read();
string NewDepartment = myReader1[0].ToString();
myReader1.Close(); TextBox myBabyId = DetailsView2.FindControl("TextBoxBabyId") as TextBox;
if (myBabyId != null)
{
String StrBabyId = "UPDATE baby SET departmentid =" + NewDepartment + " where BabyId=" + e.Values["BabyId"];
SqlCommand myCommand2 = myConnection.CreateCommand();
myCommand2.CommandText = StrBabyId;
myCommand2.ExecuteNonQuery();
//SqlCommand sqlcmd = new SqlCommand(StrBabyId, myConnection);
//sqlcmd.ExecuteNonQuery(); }
}为什么一运行就提示"在没有任何数据时进行无效的读取尝试"?而且DropDownList里没有填充进我要的东西~
{
GridViewMove.DataBind();
DropDownList myDDNewUnit = DetailsView2.FindControl("DDNewUnit") as DropDownList;
string connectionString = ConfigurationManager.ConnectionStrings["MyDB"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
String StrQ = "select unitid from unit where 单位名称='" + myDDNewUnit.SelectedValue.ToString() + "'";
SqlCommand myCommand = new SqlCommand(StrQ, myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();
myReader.Read();
string NewUnit;
NewUnit = myReader[0].ToString();
myReader.Close(); DropDownList myDDNewDepartment = DetailsView2.FindControl("DDNewDepartment") as DropDownList;
String StrQDepartmentId = "select departmentid from department where 部门名称='" + myDDNewDepartment.SelectedValue.ToString() + "' and unitid=" + NewUnit;
SqlCommand myCommand1 = new SqlCommand(StrQDepartmentId, myConnection);
SqlDataReader myReader1 = myCommand1.ExecuteReader();
myReader1.Read();
string NewDepartment = myReader1[0].ToString();
myReader1.Close(); TextBox myBabyId = DetailsView2.FindControl("TextBoxBabyId") as TextBox;
if (myBabyId != null)
{
String StrBabyId = "UPDATE baby SET departmentid =" + NewDepartment + " where BabyId=" + e.Values["BabyId"];
SqlCommand myCommand2 = myConnection.CreateCommand();
myCommand2.CommandText = StrBabyId;
myCommand2.ExecuteNonQuery();
//SqlCommand sqlcmd = new SqlCommand(StrBabyId, myConnection);
//sqlcmd.ExecuteNonQuery(); }
}为什么一运行就提示"在没有任何数据时进行无效的读取尝试"?而且DropDownList里没有填充进我要的东西~
解决方案 »
- 调用MagicAjax控件时,页面原有的JS脚本全部失效
- ASP.net有没有什么好的支持鼠标拖拽放入拉出的控件没?
- [简单问题]数据库B向数据库A更新数据.
- 我写的一个ASP.Net的程序,一个人使用没什么关系,但几个人同时使用就会死掉!请高手指点,急!
- 怎样判断IE是否接收Cookies?
- 有没人帮我下?.net网页无法打开的问题
- 如何判断驱动器类型?类似于vbscript中得drive对象drivetype。
- 关于Datagrid,在线等待
- datalist中的数据绑定问题。
- session有效时间是多长?怎样设置session的有效时间?
- 如何实现DataGrid中嵌套控件(如DropDownList)的事件触发?
- FreeTextBox不能上传图片,哪位帮帮我?我都弄了几天了,不知什么原因?
string NewUnit;
NewUnit = myReader[0].ToString();
myReader.Close();改--> if (myReader.Read())
{
string NewUnit;
NewUnit = myReader[0].ToString();
}
myReader.Close();