vb.net - How to get column ("id") value from datagridview with visual basic .net -


i have datagridview displays data database. on every row have added button text value "approve". when user clicks on button, want approved column on database changed 0 1. question how know button on row clicked. like, "update request set approved=1 id=???". , don't want show auto increment id column on datagridview user.

this should give general idea. uses sqlite can sub db. used generic index column name dgv. can leave out confirmation dialog, too, of course.

private sub mydgv_cellcontentclick(sender object, e datagridviewcelleventargs) handles mydgv.cellcontentclick     if typeof directcast(sender, datagridview).columns(e.columnindex) datagridviewbuttoncolumn andalso e.rowindex >= 0         select case e.columnindex             case mydgv.columns("approvebutton_col_name").index                 dim dr dialogresult = messagebox.show("are sure want approve this?", "confirm approval", messageboxbuttons.yesno, messageboxicon.question)                 if dr = windows.forms.dialogresult.yes                     dim cmd sqlitecommand = condata.createcommand                     cmd.commandtext = "update request set approved = 1 id = " & cint(mydgv.rows(e.rowindex).cells("myindex_col_name").value)                     dim rst integer                     rst = cmd.executenonquery()                     if rst <> 0                         'success                     else                         'failure                     end if                 end if         end select     end if  end sub 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -