0

I'm currently building a VB.net Application and I'm having a problem on reading out records to use in making another record or for computations. For example: table A records will be read and will compute an output to be saved on table B. Tried to use reader on this but i dont seem to get the right syntax. Anyone who could help me out on this? thanks!

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by __avd
0

well, I am not much sure if this helps...

You cud use ExecuteReader and store the values in some variable and then use those variables to be stored in other table entry..

for eg:

Dim con As SqlConnection
Dim cmd As SqlCommand
Dim query As String = ""
Dim a As String 
Dim b As Integer
Dim dr As SqlDataReader

con = New SqlConnection(". . . . ")
query = ("SELECT * FROM MYTABLE1")
con.open()

cmd = New SqlCommand(query,con)

dr = cmd.ExecuteReader

While dr.Read
   a = GetString(0)
   b = GetInt32(1)
End While

Dim query2 As String = ""
Dim cmd2 As SqlCommand

query2 = "INSERT INTO MYTABLE2 VALUES(' " & a & "','" & B "')"
cmd2 = New SqlCommand(query2,con)

cmd2.ExecuteNonQuery

con.Close()
dr.Close()
0

well, I am not much sure if this helps...

You cud use ExecuteReader and store the values in some variable and then use those variables to be stored in other table entry..

for eg:

Dim con As SqlConnection
Dim cmd As SqlCommand
Dim query As String = ""
Dim a As String 
Dim b As Integer
Dim dr As SqlDataReader

con = New SqlConnection(". . . . ")
query = ("SELECT * FROM MYTABLE1")
con.open()

cmd = New SqlCommand(query,con)

dr = cmd.ExecuteReader

While dr.Read
   a = GetString(0)
   b = GetInt32(1)
End While

Dim query2 As String = ""
Dim cmd2 As SqlCommand

query2 = "INSERT INTO MYTABLE2 VALUES(' " & a & "','" & B "')"
cmd2 = New SqlCommand(query2,con)

cmd2.ExecuteNonQuery

con.Close()
dr.Close()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.