2017-08-18 80 views
0

我正在開發一個web工具,它將日期輸入到SQL表中。 它的工作原理,但它需要改進,我不經常使用VB。 [![1]] [1]如何使用VBA複選框刪除選定的SQL條目

我想要的是該工具刪除,點擊按鈕「從我的表中的每個SQL條目(GridView),我把檢查使用Microsoft Visual Studio與ASP/VB.Net

編輯林:在複選框

我如何代碼,在VB.Net

EDIT?設計規範

<div class="style1"> 
    &nbsp; 
    <b> Datum:&nbsp;&nbsp;&nbsp;&nbsp; 
    <BDP:BasicDatePicker ID="datum" runat="server" DateFormat="d" /> 
    </b>&nbsp;&nbsp; 
    <b>Bezeichnung: 
    <asp:TextBox ID="txtBezeich" runat="server" Height="18px" Width="180px"></asp:TextBox> 
    </b>&nbsp;&nbsp; 
    <b>Faktor : 
    <asp:TextBox ID="txtfaktor" runat="server" Height="18px" Width="180px"></asp:TextBox> 
    </b>&nbsp;&nbsp; 
    <br /> 
    <b> 
    <asp:Button ID="cmdAdd" runat="server" Height="22px" 
     style="color: #FFFFFF; font-weight: 700; background-color: #006666" Text="Add" 
     Width="62px" /> 
    &nbsp;&nbsp;<asp:Button ID="cmdDelete" runat="server" Height="22px" 
     style="color: #FFFFFF; font-weight: 700; background-color: #006666" 
     Text="Delete" Width="62px" /> 

    &nbsp;&nbsp;<asp:Button ID="cmdUpdate" runat="server" Height="22px" 
     style="color: #FFFFFF; font-weight: 700; background-color: #006666" 
     Text="Update" Width="62px" /> 
    &nbsp; 
    </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> 

編輯:功能代碼

Partial Public Class FeiertagsTool 

Inherits System.Web.UI.Page 

Dim adoBIWEB_BIUSERLogin As New ADODB.Recordset 
Dim adoDWH As New ADODB.Connection 

Dim cred As ReportServerCredentials 
Dim Dstr As String 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    'If UserName = "" Or Pwd = "" Then 
    ' 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 As Object, ByVal e As EventArgs) Handles cmdUpdate.Click 
    adoDWH.Open() 

    If txtfaktor.Text <> "" Then 

     adoDWH.Execute("update External_Inputs.VOXPARK.Feiertag set Faktor = " & Replace(txtfaktor.Text, ",", ".") & " where Datum = convert(date,'" & datum.Text & "',104)") 
    End If 
    If txtBezeich.Text <> "" Then 
     adoDWH.Execute("update External_Inputs.VOXPARK.Feiertag set Bezeichnung = '" & txtBezeich.Text & "' where Datum = convert(date,'" & datum.Text & "',104)") 
    End If 
    GridView1.DataBind() 
    adoDWH.Close() 
End Sub 

Protected Sub cmdDelete_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdDelete.Click 
    adoDWH.Open() 
    adoDWH.Execute("delete from External_Inputs.VOXPARK.Feiertag where Datum = convert(date,'" & datum.Text & "',104)") 
    GridView1.DataBind() 
    adoDWH.Close() 
End Sub 


Protected Sub cmdAdd_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdAdd.Click 
    adoDWH.Open() 
    adoDWH.Execute("insert into 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

+1

爲什麼你想要一個Web應用程序的VBA?向我們展示迄今爲止您嘗試過的代碼。 –

+0

添加好代碼 –

回答

1

對不起,在取回此的延遲。昨天太熱了,所以我去了泳池。

在你的刪除命令中,你需要遍歷GridView的內容來查找被檢查的行。一旦你有了這一行,你就可以輕鬆地獲得需要刪除的假期文本。你需要遍歷GridView本身(而不是基礎數據,這是比較常見的),因爲複選框沒有被綁定。

要通過GridView循環,使用這樣的:

Protected Sub cmdDelete_Click(sender As Object, e As EventArgs) 
    For Each row As GridViewRow In GridView1.Rows 
     Dim test As CheckBox 
     test = CType(row.Cells(0).Controls(1), CheckBox) 
     If test.Checked = True Then 
      MsgBox(row.Cells(1).Text + " must be deleted") 
     End If 
    Next 
End Sub 

顯然在那裏我有一個消息框,你需要建立,而不是SQL命令字符串刪除的日期匹配row.Cells(1) 。文本。你現在應該有足夠的時間來自己解決問題。如果您需要進一步的幫助,請隨時與我聯繫。

+0

幫助我很多,它嘗試了幾次後就可以工作了。非常感謝你 –

+0

很高興有幫助。請將問題標記爲已回答。@ RobertD.M –