Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Currentrow syntax issue

Currentrow syntax issue

Scheduled Pinned Locked Moved Visual Basic
helpdatabasequestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hansduncan
    wrote on last edited by
    #1

    I am trying to run an insert for each row on a datagridview that is selected (checkbox on 0 column index). My problem is that the @articleID parameter is not selected from the correct row. I want the to pick up the articleID from the row that is being iterated through. Looks like the currentrow syntax isn't working. Any suggestions? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myCmd As New SqlCommand("sp_Create_NewPriceListLine", MDIParent1.Conn) myCmd.CommandType = CommandType.StoredProcedure For Each Row As DataGridViewRow In Article_searchDataGridView.Rows Dim include As DataGridViewCheckBoxCell = TryCast(Row.Cells("Select_Article"), DataGridViewCheckBoxCell) If Row.Cells("Select_Article").Value = True Then MDIParent1.Conn.Open() Dim discountID As SqlParameter = myCmd.Parameters.AddWithValue("@discountID", Me.DiscountIdTextBox1.Text) discountID.Direction = ParameterDirection.Input Dim articleID As SqlParameter = myCmd.Parameters.AddWithValue("@articleID", Me.Article_searchDataGridView.Item(7, Me.Article_searchDataGridView.CurrentRow.Index).Value) 'Me.Article_searchDataGridView.CurrentRow.Index).Value) articleID.Direction = ParameterDirection.Input Dim userID As SqlParameter = myCmd.Parameters.AddWithValue("@userID", MDIParent1.userid) userID.Direction = ParameterDirection.Input Dim myReader As SqlDataReader = myCmd.ExecuteReader() myReader.Close() MDIParent1.Conn.Close() End If myCmd.Parameters.Clear() Next End Sub

    H 1 Reply Last reply
    0
    • H Hansduncan

      I am trying to run an insert for each row on a datagridview that is selected (checkbox on 0 column index). My problem is that the @articleID parameter is not selected from the correct row. I want the to pick up the articleID from the row that is being iterated through. Looks like the currentrow syntax isn't working. Any suggestions? Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myCmd As New SqlCommand("sp_Create_NewPriceListLine", MDIParent1.Conn) myCmd.CommandType = CommandType.StoredProcedure For Each Row As DataGridViewRow In Article_searchDataGridView.Rows Dim include As DataGridViewCheckBoxCell = TryCast(Row.Cells("Select_Article"), DataGridViewCheckBoxCell) If Row.Cells("Select_Article").Value = True Then MDIParent1.Conn.Open() Dim discountID As SqlParameter = myCmd.Parameters.AddWithValue("@discountID", Me.DiscountIdTextBox1.Text) discountID.Direction = ParameterDirection.Input Dim articleID As SqlParameter = myCmd.Parameters.AddWithValue("@articleID", Me.Article_searchDataGridView.Item(7, Me.Article_searchDataGridView.CurrentRow.Index).Value) 'Me.Article_searchDataGridView.CurrentRow.Index).Value) articleID.Direction = ParameterDirection.Input Dim userID As SqlParameter = myCmd.Parameters.AddWithValue("@userID", MDIParent1.userid) userID.Direction = ParameterDirection.Input Dim myReader As SqlDataReader = myCmd.ExecuteReader() myReader.Close() MDIParent1.Conn.Close() End If myCmd.Parameters.Clear() Next End Sub

      H Offline
      H Offline
      Hansduncan
      wrote on last edited by
      #2

      Never mind....found the answer :) Dim articleID As SqlParameter = myCmd.Parameters.AddWithValue("@articleID", Row.Cells("DataGridViewTextBoxColumn1").Value) 'Me.Article_searchDataGridView.CurrentRow.Index).Value) articleID.Direction = ParameterDirection.Input

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups