c#中如何解决不包含的定义
using System;using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;
using
public partial class WebForm8 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
int id;
DataSet data =new DataSet();
StreamReader sr = new StreamReader(Server.MapPath("leave.xml"));
StreamWriter sw;
DataTable dt = new DataTable();
DataRow dr;
string str;
str = sr.ReadingLine();
data.ReadXml(sr);
sr.Close();
dt = data.Tables["leave"];
dr = dt.NewRow();
if (dt.Rows.Count == 0) id = 1;
else
id = dt.Rows.Count + 1;
dr["UserId"] = id;
dr["UserName"] = TextBox1.Text;
dr["Email"] = TextBox2.Text;
dr["PostDate"] = DateTime.Now;
dr["Words"] = TextBox3.Text;
dt.Rows.Add(dr);
sw = new StreamWriter(Server.MapPath("leave.xml"),false);
sw.WriteLine(str);
sw.Close();
sw = new StreamWriter(Server.MapPath("leave.xml"),true);
data.WriterXml(sw);
sw.Close();
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
Response.Write("\t\t留言已被保存");
string name = TextBox1.Text;
string email = TextBox2.Text;
SqlConnection con = new SqlConnection("server=C29\\SQLEXPRESS;database=reg;UID=sa;PWD=sa;");
string str = "select * from [reg_1] where 姓名='" + TextBox1.Text + "'and 电子邮件='" + TextBox2.Text + "'";
con.Open(); // 打开连接
SqlCommand cmd = new SqlCommand(str, con); // 创建Command对象
SqlDataReader dr = cmd.ExecuteReader(); // 执行ExecuteReader()方法
if (dr.Read())
{
Response.Write("<script>alert('留言成功');location='WebForm8.aspx';</script>");
}
else
{
Response.Write("<script>alert('提交失败!');location='WebForm8.aspx';</script>");
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm6.aspx");
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Response.Redirect("WebForm9.aspx");
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
}
6个错误如下:
“”并不包含“ReadingLine”的定义
“System.Data.DataSet”并不包含“WriterXml”的定义
已在此范围定义了名为“str”的局部变量。
已在此范围定义了名为“dr”的局部变量
无法将类型“System.Data.SqlClient.SqlDataReader”隐式转换为“System.Data.DataRow”
“System.Data.DataRow”并不包含“Read”的定义