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.IO;
public partial class UserWork_Bottom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string status="未读";
string Name = SelectName();
SqlConnection con=new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
string sql = "select * from Email,Employee where Email.Meetname='" + Name + "' and status='" + status + "' ";
SqlCommand com = new SqlCommand(sql,con);
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
Response.Write("<bgsound src='D:\\OA_Test\\你有新的消息,请注意查收!hun(NEW59).mp3' autostart='true'>");
}
con.Close();
if (!IsPostBack)
{
Bind();
}
}
protected void bnQuery_ServerClick(object sender, EventArgs e)
{ }
public void Bind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
string Name=SelectName();
string sql = "select * from Email,Employee where Email.Meetname='" + Name + "' and Email.sendname=Employee.username order by sid desc "; SqlDataAdapter da = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
//while (dr.Read())
//{
// string Meetname = dr["Meetname"].ToString();
// string[] a;
// a = Meetname.Split(';');
// for (int i = 0; i < a.Length; i++)
// {
// string c = a[i].ToString();
// string b = ChaXun();
// if (c == b)
// { // }
// } //}
//con.Close();
}
public string SelectName()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
string sql = "select Name from Employee where username='"+Session["UserName"].ToString()+"'";
SqlCommand com = new SqlCommand(sql,con);
SqlDataReader dr = com.ExecuteReader();
dr.Read();
string Name = dr.GetValue(0).ToString();
return Name;
}
protected void bnQuery_ServerClick1(object sender, EventArgs e)
{
if (this.txFDate.Value == "" || this.txTDate.Value == "")
{
Response.Write("<script>alert('请选择时间!')</script>");
}
else
{
DateTime FD = Convert.ToDateTime(this.txFDate.Value);
DateTime TD = Convert.ToDateTime(this.txTDate.Value);
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open(); string sql = "select * from Email,Employee where Pubdate between '" + FD + "' and '" + TD + "' and sendname='" + Session["UserName"].ToString() + "' and Email.sendname=Employee.username";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
this.Label1.Text = "共" + ds.Tables[0].Rows.Count + "记录";
con.Close();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
int sid = Convert.ToInt32(GridView1.DataKeys[e.NewEditIndex].Value.ToString());
string status = "已查看";
string sql = "update Email set Status='"+status+"' where sid="+sid+" ";
SqlCommand com = new SqlCommand(sql,con);
com.ExecuteNonQuery();
con.Close();
Response.Redirect("../MailRead1.aspx?sid="+sid+"");
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{ SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
int sid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
string sql = "select Appurtenance from Email where sid=" + sid + "";
SqlCommand com = new SqlCommand(sql,con);
SqlDataReader dr = com.ExecuteReader();
dr.Read();
string ss=dr["Appurtenance"].ToString();
string[] a = ss.Split(';');
string url = "";
for (int i = 0; i < a.Length; i++)
{
string b = a[i];
url = Server.MapPath("~") + "\\upfiles\\" + b;
break;
}
if(File.Exists(url))
{
File.Delete(url);
}
SqlConnection con1 = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con1.Open();
string sql1 = "delete from Email where sid=" + sid + "";
SqlCommand com1 = new SqlCommand(sql1, con1);
com1.ExecuteNonQuery();
Response.Write("<script>alert('删除成功!')</script>"); con1.Close();
Bind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
}
}
}
}
错误提示:string sql = "select Name from Employee where username='"+Session["UserName"].ToString()+"'";
——>用户代码为处理NullReferenceException 未将对象引用设置到对象的实例
麻烦各位高手帮忙。
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.IO;
public partial class UserWork_Bottom : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string status="未读";
string Name = SelectName();
SqlConnection con=new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
string sql = "select * from Email,Employee where Email.Meetname='" + Name + "' and status='" + status + "' ";
SqlCommand com = new SqlCommand(sql,con);
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
Response.Write("<bgsound src='D:\\OA_Test\\你有新的消息,请注意查收!hun(NEW59).mp3' autostart='true'>");
}
con.Close();
if (!IsPostBack)
{
Bind();
}
}
protected void bnQuery_ServerClick(object sender, EventArgs e)
{ }
public void Bind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
string Name=SelectName();
string sql = "select * from Email,Employee where Email.Meetname='" + Name + "' and Email.sendname=Employee.username order by sid desc "; SqlDataAdapter da = new SqlDataAdapter(sql,con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
//while (dr.Read())
//{
// string Meetname = dr["Meetname"].ToString();
// string[] a;
// a = Meetname.Split(';');
// for (int i = 0; i < a.Length; i++)
// {
// string c = a[i].ToString();
// string b = ChaXun();
// if (c == b)
// { // }
// } //}
//con.Close();
}
public string SelectName()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
string sql = "select Name from Employee where username='"+Session["UserName"].ToString()+"'";
SqlCommand com = new SqlCommand(sql,con);
SqlDataReader dr = com.ExecuteReader();
dr.Read();
string Name = dr.GetValue(0).ToString();
return Name;
}
protected void bnQuery_ServerClick1(object sender, EventArgs e)
{
if (this.txFDate.Value == "" || this.txTDate.Value == "")
{
Response.Write("<script>alert('请选择时间!')</script>");
}
else
{
DateTime FD = Convert.ToDateTime(this.txFDate.Value);
DateTime TD = Convert.ToDateTime(this.txTDate.Value);
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open(); string sql = "select * from Email,Employee where Pubdate between '" + FD + "' and '" + TD + "' and sendname='" + Session["UserName"].ToString() + "' and Email.sendname=Employee.username";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
this.Label1.Text = "共" + ds.Tables[0].Rows.Count + "记录";
con.Close();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
int sid = Convert.ToInt32(GridView1.DataKeys[e.NewEditIndex].Value.ToString());
string status = "已查看";
string sql = "update Email set Status='"+status+"' where sid="+sid+" ";
SqlCommand com = new SqlCommand(sql,con);
com.ExecuteNonQuery();
con.Close();
Response.Redirect("../MailRead1.aspx?sid="+sid+"");
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{ SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con.Open();
int sid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
string sql = "select Appurtenance from Email where sid=" + sid + "";
SqlCommand com = new SqlCommand(sql,con);
SqlDataReader dr = com.ExecuteReader();
dr.Read();
string ss=dr["Appurtenance"].ToString();
string[] a = ss.Split(';');
string url = "";
for (int i = 0; i < a.Length; i++)
{
string b = a[i];
url = Server.MapPath("~") + "\\upfiles\\" + b;
break;
}
if(File.Exists(url))
{
File.Delete(url);
}
SqlConnection con1 = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
con1.Open();
string sql1 = "delete from Email where sid=" + sid + "";
SqlCommand com1 = new SqlCommand(sql1, con1);
com1.ExecuteNonQuery();
Response.Write("<script>alert('删除成功!')</script>"); con1.Close();
Bind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
}
}
}
}
错误提示:string sql = "select Name from Employee where username='"+Session["UserName"].ToString()+"'";
——>用户代码为处理NullReferenceException 未将对象引用设置到对象的实例
麻烦各位高手帮忙。
解决方案 »
- js提示“未截断的字符串变量”
- Menu控件的一个菜单项点击后不能处于选定状态
- sql数据库连接问题求助!!
- 怎么解决用UnicodeEncoding转码后.net md5加密与asp md5不兼容的问题?
- 有头存储过程调用的问题?(在线等.....)
- 急急急!十万火急!究竟怎么回事!谁能告诉我????
- 请教:如何运行dcomcnfg设置excel程序的权限?
- VS2013母版页中调整ContentPlaceHolder1控件大小和位置
- do-while和while两个循环语句的不同点在哪里
- 请问如何将首页“网站访问量”的7位数字用图片来显示?在线等待,Thanks!
- asp.net 如何判断是否点击html控件的button的值
- 怎么操作gridview中的数据?
或者变量不是全局的
很多ASP.net初学者都以为Page_Load方法是万能的
我用这种方法,还是提示同样的错误,叫高手继续指点,谢谢!