我的asp.net不能调试了,由于只是改一个页面,觉的不调试也行吧。仔细检查一下代码就可以了。
可是今天碰到的问题实在是没有检查出来,后来把代码拷贝到笔记本上调试,单步跟踪一下就找出问题来了!
public function getinsertsql() as string
dim strsql as string
strsql = string.format("insert into {0}(inputid,itemid, 数据) values({1},{2},{3});", _tabledata, _reportid, _itemid, _value)
return strsql
end function
public function getinsertsql(byval ddl as dropdownlist) as string
if ddl.items.count = 0 then
return getinsertsql 这里少了括号,应该是return getinsertsql()
因为在vb.net中函数名代表要返回的对象,编译不会出现错误。
如果是直接用getinsertsql的话是个nothing
如果是getinsertsql()表示调用上面的重载函数getinsertsql(),这样才是正确的
可以这样理解: 系统隐式的声明了一个这样的变量,变量名是函数名,类型是函数的返回类型
end if
dim strsql as string = ""
dim v as double
dim sel as string = ddl.selectedvalue
for each item as listitem in ddl.items
v = iif(item.value = sel, _value, 0)
strsql &= string.format("insert into {0}(inputid,itemid,数据,版种) values({1},{2},{3},{4});", _tabledata, _reportid, _itemid, v, item.text.trim())
next
return strsql
end function
真是个很隐蔽的错误,以后要注意了,括号自己加上的好(以前都是vb.net自动加上括号的)
对于这样的问题,编译器应该提出警告才对,或者当取消用函数名来代表返回值。
虽然msdn是这样赞美的:
将返回值分配给函数名的优点是,直到程序遇到 exit function 或 end function 语句时函数才返回控制。这样就可以先分配一个初步的值,以后如有必要再进行调整。
