How to Get effected rows from SQl in vb.net

  • Dim ii As Integer = 0

    Try
      Dim con As New SqlConnection(")
    con.Open()
    Dim cm As New SqlCommand("select * from aa", con)
    Dim da As New SqlDataAdapter(cm)
    Dim dt As New DataTable
    da.Fill(dt)
    Dim cmd As SqlCommand

    For i As Integer = 0 To dt.Rows.Count - 1
    cmd = New SqlCommand("insert into bb (b) values('" + dt.Rows(i)("a") + "')", con)
    cmd.ExecuteNonQuery()
    ii += 1
    Next

    This is another way to acheive effected rows

    'Dim lrd As SqlDataReader = cmd.ExecuteReader() ' Execute Reader has function to return affected rows

    'MessageBox.Show(lrd.RecordsAffected)


    MessageBox.Show("No of Rows Affected" + ii.ToString)
    Catch ex As Exception
    MessageBox.Show("Execution Failed - No of Rows Affected " + ii.ToString + vbNewLine + vbNewLine + ex.Message)
    End Try

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

    Optimum Creative