等待用户输入,然后odbcdatareader再次读取 [英] Wait for user input before odbcdatareader reads again

查看:54
本文介绍了等待用户输入,然后odbcdatareader再次读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里有一个将从数据库读取的代码块,我要的是让第一个odbcdatareader在可以再次读取数据库之前等待新用户输入.我该怎么做呢?在此先感谢您的帮助..

i have a code block here that will read from a database, what i want is for the first odbcdatareader to wait for a new user input before it could read again the database.. how may i do this exactly? thanks in advance for any help..

<br />
<pre lang="vb">Public Sub find_studs()<br />
        Dim connection As New OdbcConnection<br />
        Dim dr As OdbcDataReader<br />
        Dim command As OdbcCommand<br />
        Try<br />
            '' Open Connection<br />
            connection = New OdbcConnection(ConnStr)<br />
            connection.Open()<br />
            command = New OdbcCommand("select * from schedule where sched_code = ''" & TextBox1.Text & "''", connection)<br />
            dr = command.ExecuteReader()<br />
            Dim flag As Boolean = False<br />
            While (dr.Read())<br />
                flag = True<br />
                dr.Close()<br />
                connection.Close()<br />
                connection = New OdbcConnection(ConnStr)<br />
                connection.Open()<br />
                command = New OdbcCommand("select * from student_history where crs_name = ''" & dr(1).ToString & "'' and s_year = ''" & dr(2).ToString & "'' and block = ''" & dr(3).ToString & "''", connection)<br />
                dr = command.ExecuteReader()<br />
                studnum.Text = dr(0).ToString<br />
<br />
                dr.Close()<br />
                connection.Close()<br />
                connection = New OdbcConnection(ConnStr)<br />
                connection.Open()<br />
                command = New OdbcCommand("select * from student where stud_num = ''" & studnum.Text & "''", connection)<br />
                dr = command.ExecuteReader()<br />
                studname.Text = dr(1).ToString & ", " & dr(2).ToString & " " & dr(3).ToString<br />
<br />
                btn_next.Enabled = True<br />
                GoTo skippy<br />
            End While<br />
skippy:     If flag = False Then<br />
                MsgBox("Schedule Code not found!", MsgBoxStyle.Information, "ERROR")<br />
                btn_next.Enabled = False<br />
            End If<br />
            dr.Close()<br />
        Catch ex As Exception<br />
            '' Display error<br />
            MsgBox(ex.ToString)<br />
        Finally<br />
            '' Close Connection<br />
            connection.Close()<br />
        End Try<br />
    End Sub</pre><br />
<br />

推荐答案

您必须将此整体方法分解为较小的步骤,然后将其分解为自己的方法.您需要开始根据状态"进行思考.您可以在用户操作时维护表单或应用程序的状态.如果他们在表单的控件中添加值或给您其他输入,则应该触发表单或应用程序其他部分的更新,以便用户可以对其进行操作.

由于要做家庭作业这件事很累,所以我不能做更多的事情了.如果有人给您一个直接的答案,那么他们就不会帮您任何忙.
You have to break this monolithic method down into smaller steps and break those out into their own methods. You''ll need to start thinking in terms of "state". You maintain the state of a form or application while the user manipulates it. If they put a value in a control on the form or give you some other input, that should trigger an update of some other part of the form or application so the user can manipulate that.

I can''t go into much more than that, since this reeks of a homework assignment. If anyone gives you an outright answer, they''re not doing you any favors.


这篇关于等待用户输入,然后odbcdatareader再次读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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