Here in my code, i have a database which has table of my applicants. As you will see in the code below, i want to get the number of rows from my command text and transfer it to the string "abc"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click myr.Close() mycom.Connection = cn mycom.CommandText = "SELECT Count(Cellphone) FROM tbl_applicant where Gender='Female';" myr = mycom.ExecuteReader Dim abc As String If myr.Read Then abc = myr(0) End If myr.Close()
On the code Below i used the abc as the number of data i must acquire. Then i used the new query to get the values i wanted to and transfer them to a String Array, as you can see I Redim the universal variable Numb to abc to have its array boundery.
mycom.CommandText = "SELECT Cellphone FROM tbl_applicant where Gender='Female';" myr = mycom.ExecuteReader ReDim Numb(abc) If myr.Read Then For i As Integer = 1 To abc.ToString - 1 LOT = myr(0).ToString LOT = LOT + (myr(i).ToString + ",") <- this is where i get the error it says that index is our of range. Numb = LOT.Split(",") Next End If
In this code below, i want the values of Variable Numb() to be transferred to a multiline textbox
Dim sbText As New System.Text.StringBuilder(500) For i As Integer = 0 To Numb.Length - 2 ' This will convert the number to a string, add it to the stringbuilder ' and then append a newline to the text buffer sbText.AppendLine(Numb(i)) Next i ' Now move the buffer into the control TextBox1.Text = sbText.ToString() End Sub
The end value i must see in the textbox should be like
and so forth, please try to understand the numbers i am referring it to real phone numbers. Any help with the problem or solution maybe.. Thanks