sql server - How to delete selected SQL Entries with a VBA Checkbox -
i'm working on web tool , enters dates sql table. works needs improvent , dont use vb often. [![enter image description here][1]][1]
what want tool deletes ,with click-button" every sql entry (gridview) table , put check on checkbox
how code in vb.net?
edit : im using microsoft visual studio asp/vb.net
edit: design code
<div class="style1"> <b> datum: <bdp:basicdatepicker id="datum" runat="server" dateformat="d" /> </b> <b>bezeichnung: <asp:textbox id="txtbezeich" runat="server" height="18px" width="180px"></asp:textbox> </b> <b>faktor : <asp:textbox id="txtfaktor" runat="server" height="18px" width="180px"></asp:textbox> </b> <br /> <b> <asp:button id="cmdadd" runat="server" height="22px" style="color: #ffffff; font-weight: 700; background-color: #006666" text="add" width="62px" /> <asp:button id="cmddelete" runat="server" height="22px" style="color: #ffffff; font-weight: 700; background-color: #006666" text="delete" width="62px" /> <asp:button id="cmdupdate" runat="server" height="22px" style="color: #ffffff; font-weight: 700; background-color: #006666" text="update" width="62px" /> </b> <b><br /> definitionen für faktor: <br /> 0: ganzer feiertag <br /> 0,5 : halber feiertag <br /> 0,33 : ein-drittel feiertag <br /> usw. <br /></b> </div> <asp:gridview id="gridview1" runat="server" allowpaging="false" allowsorting="true" autogeneratecolumns="false" backcolor="#f3f3f3" captionalign="right" datasourceid="dsfeiertag" height="133px" pagesize="25" style="text-align: left; font-family: calibri; font-size: small; margin-bottom: 0px;" width="477px" > <columns> <asp:templatefield> <itemtemplate> <asp:checkbox id="chk_hid1" runat="server" /> </itemtemplate> </asp:templatefield> <asp:boundfield datafield="datum" headertext="datum" sortexpression="datum" /> <asp:boundfield datafield="bezeichnung" headertext="bezeichnung" sortexpression="bezeichnung" /> <asp:boundfield datafield="faktor" headertext="faktor" sortexpression="faktor" /> </columns> <headerstyle backcolor="#2e0a31" font-underline="false" forecolor="white" /> </asp:gridview>
edit: functions code
partial public class feiertagstool inherits system.web.ui.page dim adobiweb_biuserlogin new adodb.recordset dim adodwh new adodb.connection dim cred reportservercredentials dim dstr string protected sub page_load(byval sender object, byval e system.eventargs) handles me.load 'if username = "" or pwd = "" ' server.transfer("~/mainpage.aspx", true) ' exit sub 'end if gethit(system.web.httpcontext.current.request.url.absolutepath, request.userhostaddress) adodwh.connectionstring = "dsn=report_dwh_stage;user id=bi_web_user;password=xs4dwh;" adodwh.cursorlocation = adodb.cursorlocationenum.aduseserver end sub protected sub cmdupdate_click(byval sender object, byval e eventargs) handles cmdupdate.click adodwh.open() if txtfaktor.text <> "" adodwh.execute("update external_inputs.voxpark.feiertag set faktor = " & replace(txtfaktor.text, ",", ".") & " datum = convert(date,'" & datum.text & "',104)") end if if txtbezeich.text <> "" adodwh.execute("update external_inputs.voxpark.feiertag set bezeichnung = '" & txtbezeich.text & "' datum = convert(date,'" & datum.text & "',104)") end if gridview1.databind() adodwh.close() end sub protected sub cmddelete_click(byval sender object, byval e eventargs) handles cmddelete.click adodwh.open() adodwh.execute("delete external_inputs.voxpark.feiertag datum = convert(date,'" & datum.text & "',104)") gridview1.databind() adodwh.close() end sub protected sub cmdadd_click(byval sender object, byval e eventargs) handles cmdadd.click adodwh.open() adodwh.execute("insert external_inputs.voxpark.feiertag ([datum],[bezeichnung],[faktor]) values( convert(date,'" & datum.text & "',104) , '" & txtbezeich.text & "' ," & replace(txtfaktor.text, ",", ".") & ")") gridview1.databind() adodwh.close() end sub end class
[1]: https://i.stack.imgur.com/lnnfg.pngenter code here
sorry delay in getting this. hot yesterday, headed pool.
in delete command need loop through contents of gridview find rows checked. once have row can text of holiday needs deleting. need loop through gridview (rather underlying data, more common), because checkbox unbound.
to loop through gridview, use this:
protected sub cmddelete_click(sender object, e eventargs) each row gridviewrow in gridview1.rows dim test checkbox test = ctype(row.cells(0).controls(1), checkbox) if test.checked = true msgbox(row.cells(1).text + " must deleted") end if next end sub
obviously have message box, need build instead sql command string delete date matching row.cells(1).text. should have enough fix rest yourself. please feel free me, if need further help.
Comments
Post a Comment