how to select using array from sql table then assign to textbox sequencially?

nebrom

New member
Joined
Apr 1, 2007
Messages
1
Programming Experience
Beginner
i am using vb.net and sql server 2000.
create table mytable(firstName varchar2(40),lastName varchar2(40))
insert into mytable values('sweety','hana')
insert into mytable values('gir','gez')
insert into mytable values('aden','abebe')
insert into mytable values('helen','martin')
i want to store some names in array.
arrName()=('helen','aden','sweety')
then i want to select lastName according to the firstName given to the arrName() and to assign the selected value to textbox.
then i did as follow but it doesnot work.

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
Dim dr As SqlDataReader
'assume all variable are declared
 
 
str="select lastName from mytable where firstName in arrName()"
 
con.Open()
cmd = New SqlCommand(str, con)
dr = cmd.ExecuteReader()
While (dr.Read())
TextBox1.Text += dr.GetString(1) & Environment.NewLine
 
End While
end sub
then i will expect the lastName of 'helen','aden','sweety' in textbox1.text as

martin abebe hana.

note that the order of the selected value must be the result of the order of the array, for example if the result is 'hana abebe martin' this is wrong becuase of the order is not as i want.
helen is the first in the given array so no matter about its location in the table, her lastname must be selected before the rest values.
i think you are understanding me what i am asking so
i am looking forward for your reply.
thanks
 
Last edited by a moderator:
Back
Top