这是提示错误:
E:\wdweb\sxkxt\student.aspx.cs(62,13): error CS0029: 无法将类型“System.Data.SqlClient.SqlDataReader”隐式转换为“System.Data.SqlClient.SqlDataAdapter”
E:\wdweb\sxkxt\student.aspx.cs(63,7): error CS0117: “System.Data.SqlClient.SqlDataAdapter”并不包含对“Read”的定义
E:\wdweb\sxkxt\student.aspx.cs(70,13): error CS0117: “System.Data.SqlClient.SqlDataAdapter”并不包含对“GetString”的定义
E:\wdweb\sxkxt\student.aspx.cs(85,5): error CS0117: “System.Data.SqlClient.SqlCommand”并不包含对“Fill”的定义
E:\wdweb\sxkxt\student.aspx.cs(91,5): error CS0117: “System.Data.SqlClient.SqlCommand”并不包含对“Fill”的定义
E:\wdweb\sxkxt\student.aspx.cs(97,5): error CS0117: “System.Data.SqlClient.SqlCommand”并不包含对“Fill”的定义
E:\wdweb\sxkxt\student.aspx.cs(98,20): error CS0117: “System.Data.DataTable”并不包含对“DefalutView”的定义
E:\wdweb\sxkxt\student.aspx.cs(141,7): error CS0029: 无法将类型“string”隐式转换为“bool”
下面是我的代码:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace class_select
{
public class student:Page
{
protected System.Web.UI.WebControls.TextBox sno;
protected System.Web.UI.WebControls.TextBox spas;
protected System.Web.UI.WebControls.Button c_ent;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button cgpas;
protected System.Web.UI.WebControls.DataGrid bixiu;
protected System.Web.UI.WebControls.DataGrid xuanxiu;
protected System.Web.UI.WebControls.DataGrid kua;
public string getpas;
protected System.Web.UI.WebControls.Button bx;
protected System.Web.UI.WebControls.Button xx;
protected System.Web.UI.WebControls.Button k;
protected System.Web.UI.WebControls.HyperLink checls;
static public string getsno;
private void Page_Load(object sender,EventArgs e)
{
Session.Timeout=60;
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.c_ent.Click += new System.EventHandler(this.c_ent_click);
this.cgpas.Click += new System.EventHandler(this.cgpas_click);
this.bx.Click += new System.EventHandler(this.bx_click);
this.xx.Click += new System.EventHandler(this.xx_click);
this.k.Click += new System.EventHandler(this.k_click);
this.Load += new System.EventHandler(this.Page_Load);
}
private void c_ent_click(object sender,EventArgs e)
{
DataSet ds;
SqlDataAdapter cmd;
if (sno.Text==""||spas.Text=="")
{
Label1.Text="请输入完整信息!";
return;
}
SqlConnection myconnection = new SqlConnection("server=localhost;database=mytest;uid=sa;pwd=sa;connect timeout=120");
string sqlStr = "select * from stu where sno='"+sno.Text.ToString()+"'";
SqlCommand mycommand = new SqlCommand(sqlStr,myconnection);
mycommand.Connection.Open();
SqlDataAdapter selReader;
selReader=mycommand.ExecuteReader();
if (selReader.Read()==false)
{
Label1.Text="该学号不存在!";
return;
}
else
{
getpas = selReader.GetString(5);
mycommand.Connection.Close();
if (getpas.CompareTo(spas.Text.PadRight(20))==0)
{
Session["c_no"] = "hasin";
Label1.Text="登陆成功,开始选课!";
checls.Visible=true;
c_ent.Visible=false;
getsno = sno.Text;
checls.NavigateUrl="seecls.aspx?sno="+getsno;
Session["sno"]=getsno;
cgpas.Visible=true;
sqlStr = "select * from csee where kind=1 and cdept=(select sdept from stu where sno='"+getsno+"')";
mycommand = new SqlCommand(sqlStr,myconnection);
ds = new DataSet();
mycommand.Fill(ds,"csee");
bixiu.DataSource=ds.Tables["csee"].DefaultView;
bixiu.DataBind();
sqlStr = "select * from csee where kind=2 and cdept=(select sdept from stu where sno='"+getsno+"')";
mycommand = new SqlCommand(sqlStr,myconnection);
ds = new DataSet();
mycommand.Fill(ds,"xxiu");
xuanxiu.DataSource=ds.Tables["xxiu"].DefaultView;
xuanxiu.DataBind();
sqlStr = "select * from csee where kind=2 and cdept<>(select sdept from stu where sno='"+getsno+"')";
mycommand = new SqlCommand(sqlStr,myconnection);
ds = new DataSet();
mycommand.Fill(ds,"kua");
kua.DataSource=ds.Tables["kua"].DefalutView;
kua.DataBind();
//mycommand.Connection.Close()
}
else
{
Label1.Text="密码错误!";
}
} }
private void cgpas_click(object sender,EventArgs e)
{
if (spas.Text=="")
{
Label1.Text="你必须输入一个密码!";
return;
}
else
{
SqlConnection mycon = new SqlConnection("server=localhost;database=mytest;uid=sa;pwd=sa;connect timeout=120");
string sqlStr = "update stu set spas='"+spas.Text+"' where sno='"+getsno+"'";
SqlCommand mycmd = new SqlCommand(sqlStr,mycon);
mycmd.Connection.Open();
mycmd.ExecuteNonQuery();
mycmd.Connection.Close();
Label1.Text="密码修改成功!";
}
}
private void bx_click(object sender,EventArgs e)
{
delobj(bixiu,bx);
}
private void xx_click(object sender,EventArgs e)
{
delobj(xuanxiu,xx);
}
private void k_click(object sender,EventArgs e)
{
delobj(kua,k);
}
private void delobj(DataGrid datacla,Button disp)
{
if (disp.Text="隐藏该栏")
{
disp.Text="显示该栏";
datacla.Visible=false;
}
else
{
disp.Text="隐藏该栏";
datacla.Visible=true;
}
}
}
}