System.ArgumentOutOfRangeException: StartIndex 不能小于 0。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../../App_Data/tuohaichuanmei.mdb") + ";Persist Security Info=False";
OleDbConnection conn = new OleDbConnection(str);
conn.Open();
OleDbCommand cmd = new OleDbCommand("select * from News where ID="+Request["id"].ToString()+"",conn);
OleDbDataReader rad = cmd.ExecuteReader();
if (rad.Read())
{
BiaoTi.Text = rad["Title"].ToString();
NeiRong.Text = rad["Body"].ToString();
HiddenField1.Value = rad["Img"].ToString();
}
rad.Close();
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../../App_Data/tuohaichuanmei.mdb") + ";Persist Security Info=False";
OleDbConnection conn = new OleDbConnection(str);
conn.Open();
string Img = string.Empty;
if (FileUpload1.HasFile == true)
{
string tif = Img.Substring(Img.LastIndexOf('.'));
string NewName = DateTime.Now.ToString();
string NewStr = NewName.Replace('-', '2').Replace(':', '2').Replace(' ', '2');
FileUpload1.SaveAs(Server.MapPath("~/Admin/Img/" + NewStr + tif));
File.Delete(Server.MapPath("~/Admin/Img/" + HiddenField1.Value));
OleDbCommand cmd = new OleDbCommand("update News set Title='"+BiaoTi.Text+"',Body='"+NeiRong.Text+"',Img='"+NewStr+tif+"' where ID="+Request["id"].ToString()+"", conn);
cmd.ExecuteNonQuery();
}
else
{
OleDbCommand cmd = new OleDbCommand("insert into News(Title,Body,Img)values('" + BiaoTi.Text + "','" + NeiRong.Text + "')", conn);
cmd.ExecuteNonQuery();
}
conn.Close();
}
请教高人指点 事成之后必有重谢
------解决方案--------------------
C# code
string Img = string.Empty;
if (FileUpload1.HasFile == true)
{
string tif = Img.Substring(Img.LastIndexOf('.'));
}
------解决方案--------------------
断点吧 看看下表里的值哪个小于0