EDN Admin
Well-known member
hi, can only retrieve data from database one time with read code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; While reader.Read
RichTextBox1.AppendText(reader.GetString(0))
<span style="color:Blue; End <span style="color:Blue; While
[/code]
<br/>
here is all the code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System.Data.SqlClient
<span style="color:Blue; Imports System.Threading
<span style="color:Blue; Public <span style="color:Blue; Class Form1
<span style="color:Blue; Dim connection <span style="color:Blue; As IDbConnection = _
<span style="color:Blue; New SqlConnection(WindowsApplication1.<span style="color:Blue; My.MySettings.<span style="color:Blue; Default.testConnectionString2)
<span style="color:Blue; Dim connection2 <span style="color:Blue; As IDbConnection = _
<span style="color:Blue; New SqlConnection(WindowsApplication1.<span style="color:Blue; My.MySettings.<span style="color:Blue; Default.testConnectionString2)
<span style="color:Blue; Dim connection3 <span style="color:Blue; As IDbConnection = _
<span style="color:Blue; New SqlConnection(WindowsApplication1.<span style="color:Blue; My.MySettings.<span style="color:Blue; Default.testConnectionString2)
<span style="color:Blue; Dim cmd <span style="color:Blue; As IDbCommand = _
<span style="color:Blue; New SqlCommand(<span style="color:#A31515; "Insert INTO Table1 (column1) VALUES (0)")
<span style="color:Blue; Dim cmd2 <span style="color:Blue; As IDbCommand = _
<span style="color:Blue; New SqlCommand(<span style="color:#A31515; "SELECT column1 FROM Table1")
<span style="color:Blue; Dim cmd3 <span style="color:Blue; As IDbCommand = _
<span style="color:Blue; New SqlCommand(<span style="color:#A31515; "DELETE FROM Table1")
<span style="color:Blue; Dim threadA <span style="color:Blue; As <span style="color:Blue; New Thread(<span style="color:Blue; AddressOf thread_A)
<span style="color:Blue; Dim reader <span style="color:Blue; As IDataReader
<span style="color:Blue; Dim <span style="color:Blue; count = 0
<span style="color:Blue; Dim value = 10
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; Me.Load
Form1.CheckForIllegalCrossThreadCalls = <span style="color:Blue; False
cmd.Connection = connection
cmd2.Connection = connection2
cmd3.Connection = connection3
connection.Open()
connection2.Open()
connection3.Open()
reader = cmd2.ExecuteReader
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub thread_A()
1: <span style="color:Blue; count = <span style="color:Blue; count + 1
cmd.ExecuteNonQuery()
<span style="color:Blue; If <span style="color:Blue; count < value <span style="color:Blue; Then
Thread.Sleep(1)
<span style="color:Blue; GoTo 1
<span style="color:Blue; End <span style="color:Blue; If
Thread.Sleep(6000)
<span style="color:Blue; While reader.Read()
RichTextBox1.AppendText(reader.GetString(0))
<span style="color:Blue; End <span style="color:Blue; While
<span style="color:Blue; If RichTextBox1.Text <> <span style="color:#A31515; " " <span style="color:Blue; Then RichTextBox1.BackColor = Color.BlanchedAlmond
reader.Close()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button3_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button3.Click
reader.Close()
connection.Close()
connection2.Close()
connection3.Close()
<span style="color:Blue; End
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button1_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button1.Click
<span style="color:Blue; If <span style="color:Blue; count <> 0 <span style="color:Blue; Then <span style="color:Blue; count = 0
<span style="color:Blue; Dim threadA <span style="color:Blue; As <span style="color:Blue; New Thread(<span style="color:Blue; AddressOf thread_A)
threadA.Start()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button2_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button2.Click
threadA.Suspend()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button4_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button4.Click
cmd3.ExecuteNonQuery()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button5_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button5.Click
<span style="color:Blue; While reader.Read
RichTextBox1.AppendText(reader.GetString(0))
<span style="color:Blue; End <span style="color:Blue; While
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button6_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button6.Click
RichTextBox1.Text = <span style="color:Blue; Nothing
RichTextBox1.BackColor = Color.White
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
<br/>
ne ideas why this is so? sql database, not compact
View the full article
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; While reader.Read
RichTextBox1.AppendText(reader.GetString(0))
<span style="color:Blue; End <span style="color:Blue; While
[/code]
<br/>
here is all the code:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Imports System.Data.SqlClient
<span style="color:Blue; Imports System.Threading
<span style="color:Blue; Public <span style="color:Blue; Class Form1
<span style="color:Blue; Dim connection <span style="color:Blue; As IDbConnection = _
<span style="color:Blue; New SqlConnection(WindowsApplication1.<span style="color:Blue; My.MySettings.<span style="color:Blue; Default.testConnectionString2)
<span style="color:Blue; Dim connection2 <span style="color:Blue; As IDbConnection = _
<span style="color:Blue; New SqlConnection(WindowsApplication1.<span style="color:Blue; My.MySettings.<span style="color:Blue; Default.testConnectionString2)
<span style="color:Blue; Dim connection3 <span style="color:Blue; As IDbConnection = _
<span style="color:Blue; New SqlConnection(WindowsApplication1.<span style="color:Blue; My.MySettings.<span style="color:Blue; Default.testConnectionString2)
<span style="color:Blue; Dim cmd <span style="color:Blue; As IDbCommand = _
<span style="color:Blue; New SqlCommand(<span style="color:#A31515; "Insert INTO Table1 (column1) VALUES (0)")
<span style="color:Blue; Dim cmd2 <span style="color:Blue; As IDbCommand = _
<span style="color:Blue; New SqlCommand(<span style="color:#A31515; "SELECT column1 FROM Table1")
<span style="color:Blue; Dim cmd3 <span style="color:Blue; As IDbCommand = _
<span style="color:Blue; New SqlCommand(<span style="color:#A31515; "DELETE FROM Table1")
<span style="color:Blue; Dim threadA <span style="color:Blue; As <span style="color:Blue; New Thread(<span style="color:Blue; AddressOf thread_A)
<span style="color:Blue; Dim reader <span style="color:Blue; As IDataReader
<span style="color:Blue; Dim <span style="color:Blue; count = 0
<span style="color:Blue; Dim value = 10
<span style="color:Blue; Private <span style="color:Blue; Sub Form1_Load(<span style="color:Blue; ByVal sender <span style="color:Blue; As <span style="color:Blue; Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles <span style="color:Blue; Me.Load
Form1.CheckForIllegalCrossThreadCalls = <span style="color:Blue; False
cmd.Connection = connection
cmd2.Connection = connection2
cmd3.Connection = connection3
connection.Open()
connection2.Open()
connection3.Open()
reader = cmd2.ExecuteReader
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub thread_A()
1: <span style="color:Blue; count = <span style="color:Blue; count + 1
cmd.ExecuteNonQuery()
<span style="color:Blue; If <span style="color:Blue; count < value <span style="color:Blue; Then
Thread.Sleep(1)
<span style="color:Blue; GoTo 1
<span style="color:Blue; End <span style="color:Blue; If
Thread.Sleep(6000)
<span style="color:Blue; While reader.Read()
RichTextBox1.AppendText(reader.GetString(0))
<span style="color:Blue; End <span style="color:Blue; While
<span style="color:Blue; If RichTextBox1.Text <> <span style="color:#A31515; " " <span style="color:Blue; Then RichTextBox1.BackColor = Color.BlanchedAlmond
reader.Close()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button3_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button3.Click
reader.Close()
connection.Close()
connection2.Close()
connection3.Close()
<span style="color:Blue; End
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button1_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button1.Click
<span style="color:Blue; If <span style="color:Blue; count <> 0 <span style="color:Blue; Then <span style="color:Blue; count = 0
<span style="color:Blue; Dim threadA <span style="color:Blue; As <span style="color:Blue; New Thread(<span style="color:Blue; AddressOf thread_A)
threadA.Start()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button2_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button2.Click
threadA.Suspend()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button4_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button4.Click
cmd3.ExecuteNonQuery()
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button5_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button5.Click
<span style="color:Blue; While reader.Read
RichTextBox1.AppendText(reader.GetString(0))
<span style="color:Blue; End <span style="color:Blue; While
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; Private <span style="color:Blue; Sub Button6_Click(<span style="color:Blue; ByVal sender <span style="color:Blue; As System.Object, <span style="color:Blue; ByVal e <span style="color:Blue; As System.EventArgs) <span style="color:Blue; Handles Button6.Click
RichTextBox1.Text = <span style="color:Blue; Nothing
RichTextBox1.BackColor = Color.White
<span style="color:Blue; End <span style="color:Blue; Sub
<span style="color:Blue; End <span style="color:Blue; Class
[/code]
<br/>
ne ideas why this is so? sql database, not compact
View the full article