0

i am using visual studio 2010 with sql server 2008 as back end, i have a problem in displaying all the rows of a particular column in a textbox. i have tried this,

cmd.CommandText = "select article_no from  main where name='" & TextBox1.Text & "'"

cmd.Connection = con

 con.Open()

 Dim dr As SqlDataReader

dr = cmd.ExecuteReader

 If dr.HasRows Then

   dr.Read()

 TextBox2.Text = dr.Item("article_no")

 End If

con.Close()

But i am able to display only first row of the particular name which i enter in textbox1 instead i need to display all the rows which consist of the same name entered in textbox1 and should display in textbox2.

so please anyone help me wit hthe required logic.

thanks in advance

senthilkumar2185
  • 2,536
  • 3
  • 22
  • 36
Jigar patel
  • 215
  • 2
  • 11
  • 23

4 Answers4

0

It sounds like you need to set the TextBox to be multiline or you may need to put line breaks in manually.

Check out the same answer here: (Similar Answer)

Community
  • 1
  • 1
nycdan
  • 2,819
  • 2
  • 21
  • 33
  • article_no is the column name of the database and i need to retrieve all the values from column article_no that consist of another column name "name" of the database can u please help out. – Jigar patel Dec 09 '13 at 06:59
0

maybe you can't display all the rows because you are using a textbox. Only 1 record will be added on the textbox, also maybe you can do it by setting the textbox multiline property to true. I suggest using listbox instead, and do this

If dr.HasRows Then
   While dr.Read()
     ListBox1.Add(dr.Item("article_no"))
   End While
End If
Codemunkeee
  • 1,585
  • 5
  • 17
  • 29
0

To be able to display all rows, you'll need to loop in the datatable. Try this;

If dr.HasRows Then

 For Each _dr As DataRow In dr.Rows

   _dr.Read()

 TextBox2.Text = String.Concat(TextBox2.Text, ",", _dr.Item("article_no"))

 Next
End If

Using commas , as separators in tyour textbox2

Nadeem_MK
  • 7,533
  • 7
  • 50
  • 61
0

Why not make it Multiline with a vertical scrollbar:

 TextBox2.Multiline = True      
 TextBox2.ScrollBars = ScrollBars.Vertical

Then when you traverse, you do:

 TextBox2.Text &= dr.Item("article_no") & Environment.NewLine
Edper
  • 9,144
  • 1
  • 27
  • 46