Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8150221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:00:39+00:00 2026-06-06T15:00:39+00:00

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s

  • 0
 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim s As New Staff
    Dim strConn As String

    strConn = ConfigurationManager.ConnectionStrings("ConnectionString").ToString
    Dim conn As New SqlConnection(strConn)

    Dim strSql As String
    strSql = "SELECT StaffID FROM Staff"
    Dim cmd As New SqlCommand(strSql, conn)

    Dim daMember As New SqlDataAdapter(cmd)
    Dim ds As New DataSet

    conn.Open()
    daMember.Fill(ds, "Staff")
    Dim i As Integer = ds.Tables("Staff").Rows.Count - 1
    For Each dr As DataRow In ds.Tables("Staff").Rows
        strSql = "Update CIOPassword SET CIPassword=@CI, COPassword = @CO WHERE StaffID=@id"
        Dim cmd2 As New SqlCommand(strSql, conn)
        Dim output1 As String = ""
        Dim output2 As String = ""
        Dim random As New Random()

        Dim val, val2 As Integer
        For j As Integer = 0 To 9
            val = random.[Next](1, 36)
            val2 = random.[Next](1, 36)
            output1 += ChrW(IIf(val <= 26, 64 + val, (val - 27) + 48))
            output2 += ChrW(IIf(val2 <= 26, 64 + val2, (val2 - 27) + 48))
        Next
        cmd2.Parameters.AddWithValue("@CI", output1)
        cmd2.Parameters.AddWithValue("@CO", output2)
        cmd2.Parameters.AddWithValue("@id", dr(0))
        cmd2.ExecuteNonQuery()
    Next
    GridView1.DataBind()
    conn.Close()
End Sub

Basically I am trying to update each record with 2 random numbers each time the button was clicked,my problem now is, the system will update the record but the data was wrong. Example, by right all data should be different (randomly string) but for some row it was updated with same data but in randomly, something row1 row2 row3 has exactly same data for column 1 and 2 then row 3 has distinct data, second time, row1 row2 same data row3 ro4 with different data. It is in random sequence. When I add a MsgBox to do testing in the For loop the data was updated correctly with all different data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:00:40+00:00Added an answer on June 6, 2026 at 3:00 pm

    Each time you create a Random object, it creates a new random sequence using the current time as the seed. If you create a bunch of Random objects at the same time, they will all have the same seed and therefore will generate the same sequence. As such, you should only create one Random object and reuse that same one until you are done. Don’t keep creating new ones in the loop because if the loop runs too fast, they will end up not being “random”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Button1.Click EmptyTextBoxValues(Me)
Protected Sub btnLocalSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLocalSubmit.Click Dim logic
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim ResourceObject
codebehind Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim
Protected Sub lnkContractors_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkContractors.Click If Context.User.IsInRole("HOD")
Code for button: Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
I am using following code in rowdatabound function. Protected Sub gvwMileStone_RowDataBound(ByVal sender As System.Object,
Here is the code for the button click event; Protected Sub CompetenciesButton_Click(ByVal sender As
I use this code in my VB.Net application Protected Sub btnBHNas_Click(ByVal sender As Object,
I am using VB.NET and below code on button click event. Protected Sub ibtnSendInvites_Click(ByVal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.