处学者遇到的问题,

sukey00 2004-03-11 08:24:10
已有打开的与此连接相关联的 DataReader,必须首先将它关闭。

代码入下

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;

namespace zhousunet
{

public class zhuce : System.Web.UI.Page
{
protected ArrayList Ayear;
protected ArrayList Amonth;
protected ArrayList Adate;



string StrConn;
string StrSql;
SqlConnection MyConn;
SqlCommand MyComm;//数据库操作的变量
SqlDataReader dr;


protected System.Web.UI.WebControls.Label errormessage;
protected System.Web.UI.WebControls.RequiredFieldValidator rfv01;
protected System.Web.UI.WebControls.RequiredFieldValidator rfv02;
protected System.Web.UI.WebControls.RequiredFieldValidator rfv03;
protected System.Web.UI.WebControls.CompareValidator cv1;
protected System.Web.UI.WebControls.DropDownList day;
protected System.Web.UI.WebControls.RegularExpressionValidator rev1;
protected System.Web.UI.WebControls.TextBox messages;
protected System.Web.UI.WebControls.Button BtnOK;
protected System.Web.UI.WebControls.TextBox name;
protected System.Web.UI.WebControls.RequiredFieldValidator rfv1;
protected System.Web.UI.WebControls.TextBox password;
protected System.Web.UI.WebControls.RequiredFieldValidator rfv2;
protected System.Web.UI.WebControls.TextBox password2;
protected System.Web.UI.WebControls.RequiredFieldValidator rfv3;
protected System.Web.UI.WebControls.TextBox turename;
protected System.Web.UI.WebControls.RequiredFieldValidator rfv4;
protected System.Web.UI.WebControls.RadioButtonList sex;
protected System.Web.UI.WebControls.TextBox come;
protected System.Web.UI.WebControls.TextBox email;
protected System.Web.UI.WebControls.RegularExpressionValidator rev3;
protected System.Web.UI.WebControls.TextBox oicq;
protected System.Web.UI.WebControls.TextBox mobile;
protected System.Web.UI.WebControls.TextBox tel;
protected System.Web.UI.WebControls.RegularExpressionValidator rev2;
protected System.Web.UI.WebControls.TextBox message;








protected void BtnOK_Click(object sender,System.EventArgs e)
{
StrConn=System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
MyConn=new SqlConnection(StrConn);
MyConn.Open();
StrSql="select name from classmates where name='"+name.Text.ToString()+"'";
MyComm=new SqlCommand(StrSql,MyConn);
dr=MyComm.ExecuteReader();
if(dr.Read())
{
errormessage.Text="该用户名已经被注册,请换一个名字!";
}
else
{

if(Page.IsValid)
{

StrSql="INSERT INTO classmates (name,password,sex,come,tel,mobile,messages,email,oicq)VALUES('"; //他妈的,搞了变天,原来是性别的问题,我靠
StrSql+=name.Text.ToString()+"','"; //这里相当于连加SQL
StrSql+=password.Text.ToString()+"','";
StrSql+=sex.SelectedValue.ToString()+"','"; //why can't use SelectedItem.text ?
StrSql+=come.Text.ToString()+"','";
StrSql+=tel.Text.ToString()+"','";
StrSql+=mobile.Text.ToString()+"','";
StrSql+=messages.Text.ToString()+"','";
StrSql+=email.Text.ToString()+"','";
StrSql+=oicq.Text.ToString()+"')";

//为什么会出错,我日

dr.Close();
MyComm=new SqlCommand(StrSql,MyConn);
MyComm.ExecuteNonQuery();
Page.Response.Write("注册成功");

}
}

}
}
}




...全文
86 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧