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里没有填充进我要的东西~
解决方案 »
- 用sqlite C#数据存放的问题
- 抄了一段程序,关于“加密解密字符串的”。看不懂。
- 在自定义类中如何作到像RegistryKey那样,只能由静态类Registry创建?
- 如何使用DateTime.Parse()将字符串转换成DateTime类型
- 模板列参数加密
- webservice中的属性怎么不能设置??? 请指教! 多谢!
- sql server 2005找不到企业管理器
- 在WEB Form中的保留不了值!
- 在线等待:由于要写Coding Rule for C#,所以向各位求助有关C#代码编写规范的资料!
- ■■■怎样使DataGrid只显示DataSet的一部分列???■■■
- 帮忙看看这个时间显示方式应该怎么显示比较合理(在线等)
- 请高手指教, 有没有.net com中的CharFx的例子
string NewDepartment = myReader1[0].ToString();
myReader1.Close();
-->
if (myReader1.Read())
{
string NewDepartment = myReader1[0].ToString();
}
myReader1.Close();
中的NewDepartment找不到.