愚蠢的问题 ..... [英] Silly question .....

查看:87
本文介绍了愚蠢的问题 .....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub Cmb_Line_ID_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Cmb_Line_ID.GotFocus
    Cmb_Line_ID.Items.Clear()
    Dim Cmb_Line_ID_SQL As String = "select * from line"
    Call Fill_Combo_Box(Cmb_Line_ID_SQL)
    Do While myData.Read
        Cmb_Line_ID.Items.Add(myData.Item(0))
    Loop
End Sub

Private Function Fill_Combo_Box(ByVal ComboSQL As String)
    Dim Con As OleDbConnection
    Dim sqlCmd As OleDbCommand = New OleDbCommand(ComboSQL)
    Dim myData As OleDbDataReader
    Con = New OleDbConnection(Main_Form.ConString)
    Try
        Con.Open()
        sqlCmd.Connection = Con
        myData = sqlCmd.ExecuteReader
        Return myData
    Catch ''ex As OledbException
        Return Err.Number
    End Try
End Function



在myData阅读器为空时执行.
为什么??????

感谢和问候.



In Do While the myData reader is empty.
Why??????

Thanks and regards.

推荐答案

因为即使您正在调用Fill_Combo_Box方法,您实际上并没有使用它的返回对象.调用方法.您可能想要这样:

Because even though you''re calling the Fill_Combo_Box method, you''re not actually using it''s returned object in the calling method. You probably want this:

Dim myData as OleDbDataReader = Fill_Combo_Box(Cmb_Line_ID_SQL)



不仅如此,有问题的方法没有返回类型,应该为OleDbDataReader.



Not only that, but the method in question doesn''t have a return type, which should be OleDbDataReader.


哦,我对此感到不寒而栗.您有一个没有返回类型的函数(Fill_Combo_Box).您可以通过在成功时返回OleDbDataReader并在失败时返回数字来利用这一点.更糟糕的是,当您在Cmb_Line_ID_GotFocus中调用返回值时,您并没有捕获它.因此,由于myDataFill_Combo_Box中被声明为局部变量,并且由于您没有在Cmb_Line_ID_GotFocus中捕获Fill_Combo_Box的返回值,因此您无法在Cmb_Line_ID_GotFocus中看到它. br/>
您需要回过头来看看如何正确声明和使用函数(包括使用它们的返回值)的一些说明.
Oh, I shudder to look at this. You''ve got a function (Fill_Combo_Box) that doesn''t have a return type. And you''re taking advantage of that by returning an OleDbDataReader on success and by returning a number on failure. To make matters worse, you''re not capturing the return value when you call it in Cmb_Line_ID_GotFocus. So, since myData is declared as a local variable in Fill_Combo_Box, and since you''re not capturing the return value from Fill_Combo_Box in Cmb_Line_ID_GotFocus, you can''t see it in Cmb_Line_ID_GotFocus.

You need to go back and take a look at some instruction on how to properly declare and use functions, including using their return values.


myData在Fill_Combo_Box函数(局部变量)中声明.您无法在Cmb_Line_ID_GotFocus子菜单中看到"它.
解决方案:
1)将myData声明为全局变量(在两个过程之外)

2)传递对您的函数的引用:
myData is declared inside Fill_Combo_Box function (local variable). You can''t "see" it in your Cmb_Line_ID_GotFocus sub.
Solutions:
1) declare myData as global variable (outside both procedures)
or
2) pass reference to your function:
Private Function Fill_Combo_Box(ByVal ComboSQL As String, ByRef myData as OleDbDataReader)
''body
End Function


使用(在Cmb_Line_ID_GotFocus子目录中):


Using (in Cmb_Line_ID_GotFocus sub):

Fill_Combo_Box(Cmb_Line_ID_SQL, mData)


这篇关于愚蠢的问题 .....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆