Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

Converting the string "3,4,5" to integres like 3,4,5

$
0
0
I used the gridview with checkboxes to select each row in it.
when multiple checkboxes are checked the may variable stores the value of very first field in the gridview i.e Id in it like "3,4,5"

i used this variable to update the table but my variable contains the string but sql query required the integers..

my code is given below.....please help me ..

Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click

Dim str As String = String.Empty
Dim strname As String = String.Empty

For Each gvrow As GridViewRow In GridView1.rows
Dim chk As CheckBox = DirectCast(gvrow.FindControl("chkSelect"), CheckBox)
If chk IsNot Nothing And chk.Checked Then
str += gvrow.Cells(1).Text & ","
strname += gvrow.Cells(2).Text & ","c
End If
Next
str = str.Trim(",".ToCharArray())
' str = str.Remove("")
' Label2.Text = "Selected UserIds: <b>" & str & "</b><br/>" & "Selected UserNames: <b>" & strname & "</b>"

Dim cmd As New SqlCommand
cmd.CommandText = "Update Registration set status=1 WHERE Id in('" + Str + " ') "
cmd.Connection = mycon.con
mycon.con.Open()
cmd.ExecuteNonQuery()
Mycon.con.close()

End Sub

Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>