mysql - Save Datagridview if it is Checked by CheckboxColumn -
hello afternoon,
i have object in form , datagridview1
, save button
datagridview1
populate data database on form_load
, data show corresponding checkbox. image below
and if here code that
private sub loadtech() dim con1 mysqlconnection = new mysqlconnection("datasource=localhost;database=operations;userid=root;password=admin1950;convert 0 datetime=true") dim sql1 mysqlcommand = new mysqlcommand("select techname technicians order category asc", con1) dim ds1 dataset = new dataset dim adapter1 mysqldataadapter = new mysqldataadapter con1.open() adapter1.selectcommand = sql1 adapter1.fill(ds1, "mytable") datagridview1.datasource = ds1.tables(0) con1.close() datagridview1 .rowheadersvisible = false .columns(0).headercell.value = "technician / electrician" end datagridview1.columns.item(0).width = 150 datagridview1.columnheadersdefaultcellstyle.alignment = datagridviewcontentalignment.bottomcenter me.datagridview1.defaultcellstyle.wrapmode = datagridviewtristate.true me.datagridview1.columns(0).defaultcellstyle.alignment = datagridviewcontentalignment.middleleft dim checkboxcolumn new datagridviewcheckboxcolumn() checkboxcolumn.headertext = "tag" checkboxcolumn.width = 30 checkboxcolumn.name = "checkboxcolumn" datagridview1.columns.insert(0, checkboxcolumn) end sub
and question how can save checked row in database? lets checked of rows saved in database. (regardless of how many checked)
here code not working. :(
private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click dim conn mysqlconnection = new mysqlconnection("datasource=localhost;database=operations;userid=root;password=admin1950;convert 0 datetime=true") conn.open() dim comm mysqlcommand = new mysqlcommand() comm.connection = conn dim name string integer = 0 me.datagridview1.rows.count name = me.datagridview1.rows(0).cells(1).value comm.commandtext = "insert assignments(elecassigned) values('" & name & "')" comm.executenonquery() next conn.close() end sub
tysm future help
yes, loop incorrect. try using loop , see if fixes issue. issue, didn't use i
variable. should placed in row(i)
, looping 0 count when should 0 count - 1
dim name string integer = 0 me.datagridview1.rows.count - 1 step 1 if me.datagridview1.rows(i).cells(0).value = true name = me.datagridview1.rows(i).cells(1).value comm.commandtext = "insert assignments(elecassigned) values('" & name & "')" comm.executenonquery() end if next
Comments
Post a Comment