谁遇到过这样的问题!

如若初见 2010-07-14 04:12:07
if (oprno == "01")
{
try
{
if (recvdata.Length == 57)
{
phone = recvdata.Substring(10, 11);
businessid = recvdata.Substring(21, 8);
loginid = recvdata.Substring(33,10);
MessageBox.Show(phone+"+"+businessid+"+"+loginid);
if (QueryReginfo(loginid) > 0)
{
senddata = Getbusinessinfo(businessid) ;//在这用“快速监视”看了一下,提示 Getbusinessinfo(businessid)是一个方法,在这在给定的上下文中无效 }
else
{
senddata = "00";
}

}

}
catch (Exception ex)
{
MessageBox.Show("操作码01处出错:" + ex.Message, "01出错提示");//捕捉到的错误提示是“索引超出数组界限” }
}

请高手指点!
...全文
105 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
如若初见 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 tashiwoweiyi 的回复:]
OK了?
[/Quote]
呵呵 ok了
各位,分比较少,请谅解!
tashiwoweiyi 2010-07-14
  • 打赏
  • 举报
回复
OK了?
如若初见 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 tashiwoweiyi 的回复:]
C# code

public string Getbusinessinfo(string businessid)
{
string sendmsg = string.Empty;
string selectinfo = string.Format(@"select * from Businessinfo where Business_id='{0}'",……
[/Quote]
问题就出现在这段代码里,非常感谢!
谢谢各位的指点!
a6711145 2010-07-14
  • 打赏
  • 举报
回复
斷點 調試
myhope88 2010-07-14
  • 打赏
  • 举报
回复
都说数组超界了,那肯定是引用到无效的索引号了嘛
tashiwoweiyi 2010-07-14
  • 打赏
  • 举报
回复

string datestr = DateTime.Now.Year.ToString() + "年"+DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";

//不好意思,年后面多了个分号

string datestr = DateTime.Now.Year.ToString() + "年"+DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";
tashiwoweiyi 2010-07-14
  • 打赏
  • 举报
回复
把 MessageBox.Show()这个去掉。

还有你那获取年月日的时候,没必要那样。直接获取就可以了。

你SQL语句最好不要+号拼接。
tashiwoweiyi 2010-07-14
  • 打赏
  • 举报
回复

public string Getbusinessinfo(string businessid)
{
string sendmsg = string.Empty;
string selectinfo = string.Format(@"select * from Businessinfo where Business_id='{0}'", businessid);
string first = GetModelField("1");
string second = GetModelField("2");
string third = GetModelField("3");
string four = GetModelField("4");
string five = GetModelField("5");
try
{
SqlDataAdapter sdrq = new SqlDataAdapter(selectinfo, conn);
DataSet ds = new DataSet();
sdrq.Fill(ds, "info");
if (ds.Tables["info"].Rows.Count > 0)
{
string datestr = DateTime.Now.Year.ToString() + "年"; +DateTime.Now.Month.ToString() + "月" + DateTime.Now.Day.ToString() + "日";
string businessname = ds.Tables["info"].Rows[0]["Business_name"].ToString();
string discountinfo = ds.Tables["info"].Rows[0]["Discount_info"].ToString();
sendmsg = datestr + first + second + businessname + third + discountinfo + four + five;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
return sendmsg;
}
如若初见 2010-07-14
  • 打赏
  • 举报
回复
原来程序是调试通过的,不知道动了哪才出现这种情况的,我很郁闷!
tashiwoweiyi 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 guoke00000 的回复:]
更郁闷是偶尔会执行,能返回想要的结果
[/Quote]
能不能把Getbusinessinfo()这个方法帖出来。
如若初见 2010-07-14
  • 打赏
  • 举报
回复
public string Getbusinessinfo(string businessid)
{

string sendmsg = "information_null";
string selectinfo = "select * from Businessinfo where Business_id='"+businessid+"'";
string first = GetModelField("1");
string second = GetModelField("2");
string third = GetModelField("3");
string four = GetModelField("4");
string five = GetModelField("5");
try
{
SqlDataAdapter sdrq = new SqlDataAdapter(selectinfo,conn);
DataSet ds = new DataSet();
sdrq.Fill(ds,"info");
if (ds.Tables["info"].Rows.Count > 0)
{
DateTime dt = DateTime.Parse(System.DateTime.Now.ToShortDateString());
string datestr=dt.Year.ToString()+"年"+dt.Month.ToString()+"月"+dt.Day.ToString()+"日";
string businessname = ds.Tables["info"].Rows[0]["Business_name"].ToString();
string discountinfo = ds.Tables["info"].Rows[0]["Discount_info"].ToString();

sendmsg =datestr+first+second+businessname+third+discountinfo+four+five;
MessageBox.Show(sendmsg);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return sendmsg;
}
这是Getbusinessinfo()代码
如若初见 2010-07-14
  • 打赏
  • 举报
回复
更郁闷是偶尔会执行,能返回想要的结果
如若初见 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 tashiwoweiyi 的回复:]
引用 1 楼 guoke00000 的回复:
senddata = Getbusinessinfo(businessid) 这一句为什么不执行啊


loginid = recvdata.Substring(33,10);
这句代码截取的时候,可能以经出错了,或者这 个条件不满足 if (QueryReginfo(loginid) > 0)
[/Quote]
打过断点看过了,截取的数据没错,就是到这“senddata = Getbusinessinfo(businessid)”
senddata还是初始值:“0000”,Getbusinessinfo(businessid)没执行?
zzyhuian06142 2010-07-14
  • 打赏
  • 举报
回复
Getbusinessinfo代码贴出来看看
q107770540 2010-07-14
  • 打赏
  • 举报
回复


businessid = recvdata.Substring(21, 8); //此处打个断点,问题在此
tashiwoweiyi 2010-07-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 guoke00000 的回复:]
senddata = Getbusinessinfo(businessid) 这一句为什么不执行啊
[/Quote]

loginid = recvdata.Substring(33,10);
这句代码截取的时候,可能以经出错了,或者这 个条件不满足 if (QueryReginfo(loginid) > 0)
tashiwoweiyi 2010-07-14
  • 打赏
  • 举报
回复
catch中所出现 的错误是substring()截取的时候所出现的。

是你截取的recvdata长度不够。
如若初见 2010-07-14
  • 打赏
  • 举报
回复
senddata = Getbusinessinfo(businessid) 这一句为什么不执行啊

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧