Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi good Day , how can I loop the const storecode01 value to the whole private sub?

Other value of const storecode01 are:
VB
Const storecode01 As Integer = 1
Const storecode01 As Integer = 3
Const storecode01 As Integer = 5
Const storecode01 As Integer = 7

VB
Const storecode01 As Integer = 1
Private Sub StoreO()
    Dim s As String = ""
    

    Dim cn As New SqlClient.SqlConnection
    Dim cm As New SqlClient.SqlCommand


    cn.ConnectionString = "Server=SAMPLESESERVER;Database=Database;User Id=id; Password=pass;"
    cn.Open()
    cm.Connection = cn
    cm.CommandText = "sp_Storedproc"
    cm.CommandType = CommandType.StoredProcedure
    cm.Parameters.Add("@storecode", SqlDbType.Int).Value = storecode01

    Dim dt As New DataTable
    dt.Load(cm.ExecuteReader)

    If dt.Rows.Count > 0 Then
        Dim r As DataRow

        For Each r In dt.Rows
            s = s & r("Name").ToString & ";" & r("Address").ToString & ";" & r("Age").ToString & vbCrLf
        Next
    End If
    FolderBrowserDialog1.ShowDialog()
    Dim filename = FolderBrowserDialog1.SelectedPath & "Sample.txt"
    IO.File.WriteAllText(filename, s, System.Text.Encoding.UTF8)
    Close()
End Sub

I need to use all storecode01 value .
Thanks
Posted
Updated 14-May-15 23:43pm
v2
Comments
Tomas Takac 15-May-15 5:44am    
Not clear. What loop? The const isn't used anywhere in your code. Please be more specific.

Um...you can't declare four different values as the same name at all, let alone try and "loop" on them - it doesn't work.

It's like trying to take 4 dvds and push them all into a dvd player that only takes one - something is going to break!

If you want a number of values to use in you method, I suggest that you start looking at an array instead: https://msdn.microsoft.com/en-us/library/wak0wfyt.aspx[^]
 
Share this answer
 
A Const is a kind of a Variable that never changes after initialisation. As it's Name say's : Constant.

What I think as you want do do needs a List (perhaps of Integer) in which you write the different values und which must be iterated during the cycle ...

Greetings
Ralf
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900