本文介绍了我收到了错误(索引超出了数组的范围)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用字符文字和数字自动生成代码(SH / OPD / 2015/01),应该是自动增量,PLZ帮助我。我的代码是
string NewCode = ;
string str = ;
str = 选择Opdid From temp;
str = 从opd_reg中选择MAX(Opdid)AS'Oddid';
DataSet ds = new DataSet();
ds = c.ExecuteSQL(str);
if (ds.Tables [ 0 ]。Rows.Count > 0 )
{
string maxMainCode = ds.Tables [ 0 ]。行[ 0 ] [ Opdid]。ToString();
// int NewCount = Convert.ToInt32(Code.Substring(2))+ 1;
if (maxMainCode!= )
{
string [] arInfo = new string [ 150 ];
char [] splitter1 = {' S '};
char [] splitter2 = {' H '};
char [] splitter3 = {' / '};
char [] splitter4 = {' O'};
char [] splitter5 = {' P '};
char [] splitter6 = {' D '};
char [] splitter7 = {' / '};
char [] splitter8 = {' 2 '};
char [] splitter9 = {' 0 '};
char [] splitter10 = {' 1 '};
char [] splitter11 = {' 5 '};
char [] splitter12 = {' / '};
arInfo = maxMainCode.Split(splitter1);
arInfo = maxMainCode.Split(splitter2);
arInfo = maxMainCode.Split(splitter3);
arInfo = maxMainCode.Split(splitter4);
arInfo = maxMainCode.Split(splitter5);
arInfo = maxMainCode.Split(splitter6);
arInfo = maxMainCode.Split(splitter7);
arInfo = maxMainCode.Split(splitter8);
arInfo = maxMainCode.Split(splitter9);
arInfo = maxMainCode.Split(splitter10);
arInfo = maxMainCode.Split(splitter11);
arInfo = maxMainCode.Split(splitter12);
int OrignalNum = Convert.ToInt32(arInfo [ 180 ]。ToString( ));
int 添加;
Add = OrignalNum + 10 ;
if (Convert.ToString(OrignalNum).Length == Convert.ToString(Add).Length)
{
NewCode = maxMainCode.Replace(OrignalNum.ToString(),Add.ToString());
}
else
{
NewCode = maxMainCode.Replace( 0 + OrignalNum.ToString(),Add.ToString());
}
}
else
{
NewCode = SH / OPD / 2015/01;
}
}
else
{
NewCode = SH / OPD / 2015/01;
objs.Stmt = 插入临时(Opdid)值(' + NewCode + ');
objs.CallQuery(objs);
}
返回 NewCode;
}
解决方案
i want to auto generate code using character literals and digit like this (SH/OPD/2015/01),Is should be auto increment,plz help me.My code is
string NewCode = ""; string str = ""; str = "Select Opdid From temp"; str = "Select MAX(Opdid) AS 'Opdid' from opd_reg"; DataSet ds = new DataSet(); ds = c.ExecuteSQL(str); if (ds.Tables[0].Rows.Count > 0) { string maxMainCode = ds.Tables[0].Rows[0]["Opdid"].ToString(); // int NewCount = Convert.ToInt32(Code.Substring(2))+1; if (maxMainCode != "") { string[] arInfo = new string[150]; char[] splitter1 = { 'S' }; char[] splitter2 = { 'H' }; char[] splitter3 = { '/' }; char[] splitter4 = { 'O' }; char[] splitter5 = { 'P' }; char[] splitter6 = { 'D' }; char[] splitter7 = { '/' }; char[] splitter8 = { '2' }; char[] splitter9 = { '0' }; char[] splitter10 = { '1' }; char[] splitter11 = { '5' }; char[] splitter12 = { '/' }; arInfo = maxMainCode.Split(splitter1); arInfo = maxMainCode.Split(splitter2); arInfo = maxMainCode.Split(splitter3); arInfo = maxMainCode.Split(splitter4); arInfo = maxMainCode.Split(splitter5); arInfo = maxMainCode.Split(splitter6); arInfo = maxMainCode.Split(splitter7); arInfo = maxMainCode.Split(splitter8); arInfo = maxMainCode.Split(splitter9); arInfo = maxMainCode.Split(splitter10); arInfo = maxMainCode.Split(splitter11); arInfo = maxMainCode.Split(splitter12); int OrignalNum = Convert.ToInt32(arInfo[180].ToString()); int Add; Add = OrignalNum + 10; if (Convert.ToString(OrignalNum).Length == Convert.ToString(Add).Length) { NewCode = maxMainCode.Replace(OrignalNum.ToString(), Add.ToString()); } else { NewCode = maxMainCode.Replace("0" + OrignalNum.ToString(), Add.ToString()); } } else { NewCode = "SH/OPD/2015/01"; } } else { NewCode = "SH/OPD/2015/01"; objs.Stmt = "Insert Into temp (Opdid) values ('" + NewCode + "')"; objs.CallQuery(objs); } return NewCode; }
解决方案
这篇关于我收到了错误(索引超出了数组的范围)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!