English 中文(简体)
相当于搬走Next,movePrevois of the original vb6 in vb .net
原标题:what is the equivalent to moveNext,movePrevois of the old vb6 in vb .net

I designed a program in vb6 which lets the user navigate through the table. now I am transferring this software to vb .net.now my question is how to perform these functionalities in vb .net. here is my code that opens the database

    Dim constr As String = "data source=DESKTOP-MDOP24UGORASHY;" & "initial catalog=test;integrated security=SSPI;"
    Dim con As SqlConnection = New SqlConnection(constr)
    Dim cmd As SqlCommand = New SqlCommand("SELECT * from 
    words")
    cmd.CommandType = CommandType.Text
            cmd.Connection = con
            con.Open()
    Dim sdr As SqlDataReader = cmd.ExecuteReader()
    sdr.Read()
    TextBox1.Text = sdr("word-no").ToString
    TextBox2.Text = sdr("word").ToString
问题回答

ADO。 该网络的工作与ADO相当不同。 “ADORecordset 保持了与数据库的公开链接,这样当你通过数据编辑或浏览时,你就会改变并看到数据库中的实际内容。 ADO。 该网络在互不关联的情况下运作。 你打开了一条连接线,从数据库中检索数据,关闭连接,使用和(或)修改数据,开放连接,避免变化,然后关闭联系。 导航和修改是在与数据库脱节的数据的当地文本上进行的。

The SqlDataReader that You re used (as with all ADO.NET data Readers) provideread- only, forward- only access to the result set of a query. 每当你打电话<代码>Read时,就会有下一个记录。 这就是你想要的<代码>moveNext,但并不等于movePrevious,你不能对数据作任何改动,并影响到数据库。

您应当做的是,在您的问答中填满了<条码>的可诉,并对您的控制具有约束力。 然后,请打电话到<代码>MoveNext和BledSource,以浏览DataTable中的数据,并自动填入控制。 您对控制数据作出的任何改动将自动推向<编码>可发射<><>代码>,然后,如果需要,可将这些改动撤回数据库。

如果你无意挽救任何变化,你可以使用数据读物填满<代码>。 数据

Using connection As New SqlConnection(connectionString),
      command As New SqlCommand(query, connection)
    connection.Open()

    Using reader = command.ExecuteReader()
        Dim table As New DataTable

        table.Load(reader)
        myBindingSource.DataSource = Table
        myTextBox.DataBindingS.Add("Text", myBindingSource, "SomeColumn")
    End Using
End Using

More to follow...





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?