Home »
.NET 4.0 »
Array – using array (vb.net) to update multiple records
Array – using array (vb.net) to update multiple records
'Dim RecIDRE As String = Request.Form("reId")
If Not RecID = 0 Then
Try
'define sql conn
Dim connString As String
connString = ConfigurationManager.ConnectionStrings("MySQLConnectionString1").ToString
Dim conn As New SqlConnection(connString)
Dim cmd As New SqlCommand()
conn.ConnectionString = connString
conn.Open()
Dim printArray As Array = RecID.Split(",")
Dim i As Integer
For i = 0 To printArray.Length - 1
count = count + 1
Dim AdUpdate As String = _
"UPDATE real_estate _
"SET ad_printed = 'yes' _
"WHERE rid = " & printArray(i)
cmd.Connection = conn
cmd.CommandText = AdUpdate
cmd.ExecuteNonQuery()
Next
conn.Close()
conn.Dispose()
Catch ex As Exception
Label1.Text = "Real Estate Print Error: " & ex.Message.ToString()
Label1.Attributes.Add("style", "color: red; fonth-weight: bold;")
End Try
Label2.Text = count & " ads printed!"
Label2.Attributes.Add("style", "color: green; font-size: 12px;")
Else
Label2.Text = count & " ads printed!"
Label2.Attributes.Add("style", "color: blue; font-size: 12px;")
End If
Tags: array, ASP.NET, SQL, Visual Studio