参数名: length
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentOutOfRangeException: 索引和长度必须引用该字符串内的位置。
参数名: length
源错误:
行 45: str = "S101";
行 46: else
行 47: str = "S" + (Convert.ToInt32(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString().Substring(2, 4)) + 1);
行 48: return str;
行 49: }
堆栈跟踪:
[ArgumentOutOfRangeException: 索引和长度必须引用该字符串内的位置。
参数名: length]
System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +10662683
System.String.Substring(Int32 startIndex, Int32 length) +10
BookShelfManage.GetBookshelfID() in E:\zhz\泉州师范\web--ASP\设计\Book\App_Code\BookShelfManage.cs:47
Book.SystemSet.AddBookShelf.Page_Load(Object sender, EventArgs e) in E:\zhz\泉州师范\web--ASP\设计\Book\SystemSet\AddBookShelf.aspx.cs:19
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
2 个解决方案
#1
源码:
public class BookShelfManage
{
private string id ;
private string name;
public BookShelfManage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
DataBase data = new DataBase();
public string ID
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string GetBookshelfID()
{
DataSet ds = GetBookshelf("tb_bookshelf");
string str = "";
if (ds.Tables[0].Rows.Count == 0)
str = "S101";
else
str = "S" + (Convert.ToInt32(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString().Substring(2, 4)) + 1);
return str;
}
public int AddBookShelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name),
};
return (data.RunProc("INSERT INTO tb_bookshelf (id,name) VALUES(@id,@name)", prams));
}
public int UpdateBookshelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name),
};
return (data.RunProc("update tb_bookshelf set name=@name where id=@id", prams));
}
public int DeleteBookshelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
};
return (data.RunProc("delete from tb_bookshelf where id=@id", prams));
}
public DataSet QueryBookshelfByID(BookShelfManage bookshelfM, string name)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID+"%"),
};
return (data.RunProcReturn("select * from tb_bookshelf where id like @id", prams, name));
}
public DataSet QueryBookshelfByName(BookShelfManage bookshelfM, string name)
{
SqlParameter[] prams = {
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name+"%"),
};
return (data.RunProcReturn("select * from tb_bookshelf where name like @name", prams, name));
}
public DataSet GetBookshelf(string name)
{
return (data.RunProcReturn("select * from tb_bookshelf ORDER BY id", name));
}
}
public class BookShelfManage
{
private string id ;
private string name;
public BookShelfManage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
DataBase data = new DataBase();
public string ID
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string GetBookshelfID()
{
DataSet ds = GetBookshelf("tb_bookshelf");
string str = "";
if (ds.Tables[0].Rows.Count == 0)
str = "S101";
else
str = "S" + (Convert.ToInt32(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString().Substring(2, 4)) + 1);
return str;
}
public int AddBookShelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name),
};
return (data.RunProc("INSERT INTO tb_bookshelf (id,name) VALUES(@id,@name)", prams));
}
public int UpdateBookshelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name),
};
return (data.RunProc("update tb_bookshelf set name=@name where id=@id", prams));
}
public int DeleteBookshelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
};
return (data.RunProc("delete from tb_bookshelf where id=@id", prams));
}
public DataSet QueryBookshelfByID(BookShelfManage bookshelfM, string name)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID+"%"),
};
return (data.RunProcReturn("select * from tb_bookshelf where id like @id", prams, name));
}
public DataSet QueryBookshelfByName(BookShelfManage bookshelfM, string name)
{
SqlParameter[] prams = {
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name+"%"),
};
return (data.RunProcReturn("select * from tb_bookshelf where name like @name", prams, name));
}
public DataSet GetBookshelf(string name)
{
return (data.RunProcReturn("select * from tb_bookshelf ORDER BY id", name));
}
}
#2
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString().
Substring(2, 4)
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString()这个字符串的值长度是否满足后面截取。自己调试就知道了
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString()这个字符串的值长度是否满足后面截取。自己调试就知道了
#1
源码:
public class BookShelfManage
{
private string id ;
private string name;
public BookShelfManage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
DataBase data = new DataBase();
public string ID
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string GetBookshelfID()
{
DataSet ds = GetBookshelf("tb_bookshelf");
string str = "";
if (ds.Tables[0].Rows.Count == 0)
str = "S101";
else
str = "S" + (Convert.ToInt32(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString().Substring(2, 4)) + 1);
return str;
}
public int AddBookShelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name),
};
return (data.RunProc("INSERT INTO tb_bookshelf (id,name) VALUES(@id,@name)", prams));
}
public int UpdateBookshelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name),
};
return (data.RunProc("update tb_bookshelf set name=@name where id=@id", prams));
}
public int DeleteBookshelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
};
return (data.RunProc("delete from tb_bookshelf where id=@id", prams));
}
public DataSet QueryBookshelfByID(BookShelfManage bookshelfM, string name)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID+"%"),
};
return (data.RunProcReturn("select * from tb_bookshelf where id like @id", prams, name));
}
public DataSet QueryBookshelfByName(BookShelfManage bookshelfM, string name)
{
SqlParameter[] prams = {
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name+"%"),
};
return (data.RunProcReturn("select * from tb_bookshelf where name like @name", prams, name));
}
public DataSet GetBookshelf(string name)
{
return (data.RunProcReturn("select * from tb_bookshelf ORDER BY id", name));
}
}
public class BookShelfManage
{
private string id ;
private string name;
public BookShelfManage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
DataBase data = new DataBase();
public string ID
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string GetBookshelfID()
{
DataSet ds = GetBookshelf("tb_bookshelf");
string str = "";
if (ds.Tables[0].Rows.Count == 0)
str = "S101";
else
str = "S" + (Convert.ToInt32(ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString().Substring(2, 4)) + 1);
return str;
}
public int AddBookShelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name),
};
return (data.RunProc("INSERT INTO tb_bookshelf (id,name) VALUES(@id,@name)", prams));
}
public int UpdateBookshelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name),
};
return (data.RunProc("update tb_bookshelf set name=@name where id=@id", prams));
}
public int DeleteBookshelf(BookShelfManage bookshelfM)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID),
};
return (data.RunProc("delete from tb_bookshelf where id=@id", prams));
}
public DataSet QueryBookshelfByID(BookShelfManage bookshelfM, string name)
{
SqlParameter[] prams = {
data.MakeInParam("@id", SqlDbType.VarChar, 30, bookshelfM.ID+"%"),
};
return (data.RunProcReturn("select * from tb_bookshelf where id like @id", prams, name));
}
public DataSet QueryBookshelfByName(BookShelfManage bookshelfM, string name)
{
SqlParameter[] prams = {
data.MakeInParam("@name", SqlDbType.VarChar, 50,bookshelfM.Name+"%"),
};
return (data.RunProcReturn("select * from tb_bookshelf where name like @name", prams, name));
}
public DataSet GetBookshelf(string name)
{
return (data.RunProcReturn("select * from tb_bookshelf ORDER BY id", name));
}
}
#2
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString().
Substring(2, 4)
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString()这个字符串的值长度是否满足后面截取。自己调试就知道了
ds.Tables[0].Rows[ds.Tables[0].Rows.Count - 1][0].ToString()这个字符串的值长度是否满足后面截取。自己调试就知道了