且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

项目登录页面中的错误

更新时间:2023-12-01 16:05:04

看起来RadioButtonLoginEmail.Checked返回的是false,因此没有对字符串strqry的查询.

这导致执行未定义查询的适配器.在内部,第一个参数是 selectCommandText:一个字符串,它是SqlDataAdapter的SelectCommand属性使用的Transact-SQL SELECT语句或存储过程.
参考: MSDN:SqlDataAdapter构造函数(字符串,字符串) [
It looks like RadioButtonLoginEmail.Checked returned false and thus no query was formed for the string strqry.

This lead to execute an adapter that had no query defined. Internally, the first parameter is selectCommandText: A String that is a Transact-SQL SELECT statement or stored procedure to be used by the SelectCommand property of the SqlDataAdapter.
Refer: MSDN: SqlDataAdapter Constructor (String, String)[^]


Just make sure the query is formed properly and passed to adapter for execution.


在问一个问题之前请三思:该问题与属性CommandText有关,您会看到一个漂亮的无关代码的大片段,但没有一个像显示名称CommandText的单个片段!你觉得这很好吗?还是有意义?

自己发现问题,这是最容易发现的问题之一.当该属性的值为null时,您只需尝试使用该属性.找到使用它的所有位置,并在类似的位置放置一个断点,在调试器下运行它,并在使用之前找出该属性为null的位置.因此,修复程序将确保使用前已初始化属性(后面的字段),或者在使用前检查是否为null,如果该属性为null,则不要使用它(不要尝试取消引用空引用).

现在,我不相信以这种方式编写的或多或少的大型应用程序永远无法正常工作.看,您已经至少写了3次文字顾问"以及其他直接字符串常量.这与所谓的编程相反.您认为这样的事情可以得到支持吗?您将在开发的早期阶段迷路.请参阅:
http://en.wikipedia.org/wiki/Don%27t_repeat_yourself [
Just think a bit before asking a question: the issue is about the property CommandText, and you show a pretty big fragment of unrelated code, but not a single like showing the name CommandText! Do you think this is nice? Or can make any sense?

Find the problem by yourself, it''s one of the easiest to find. You simply try to use this property when it''s value is null. Find all places where you use it and put a breakpoint in the like before, run it under debugger and find out where the property is null before use. Accordingly, the fix will either make sure the property (the field behind) is initialized before use, or you check if for null before use and don''t use it if it is null (don''t try to de-reference the null reference).

Now, I don''t believe a more or less big application written in such manner can ever work. Look, you have written the literal "Consultant" at least 3 times, as well as other immediate string constants. This is opposite to what is called programming. Do you think such things can be supported? You will get lost in early stages of development. Please see:
http://en.wikipedia.org/wiki/Don%27t_repeat_yourself[^].

—SA