提交按钮在VB中不起作用

时间:2015-03-24 00:15:47

标签: asp.net vb.net button insert

您好我已经重新设计了我的提交表单,并尝试在表单向导之外执行此操作,但我无法触发提交按钮并将项目插入数据库。我已经发短信连接,数据库字符串和DDL中的选择所有工作。并且没有抛出错误或警报。网页加载,我可以选择DDL和按钮但它不清除页面或插入数据库表,任何帮助,因为我的错误将非常感谢。提前谢谢凯文。

ASPX代码

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="WebForm3.aspx.vb" Inherits="WebApplication4.WebForm3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    Product Name:
     <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="product_name" DataValueField="product_name">
 </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Incident_TrackerConnectionString %>" SelectCommand="select product_name from dbo.products"></asp:SqlDataSource>
    <br />
    Product Description:
    <asp:TextBox ID="Product_Description" runat="server" Text='<%# Bind("Product_Description") %>'></asp:TextBox>
    Product ID:
    <asp:TextBox ID="ProductID" runat="server" Text='<%# Bind("ProductID")%>'></asp:TextBox>
    <br />
    Sub Product Name:
    <asp:TextBox ID="Sub_ProductName" runat="server" Text='<%# Bind("Sub_ProductName")%>'></asp:TextBox>
    Sub Product Description:
    <asp:TextBox ID="Sub_ProductDescription" runat="server" Text='<%# Bind("Sub_ProductDescription")%>'></asp:TextBox>
    <br />
    <br />
    <asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
</asp:Content>

ASPX.VB代码

Imports System.Data.OleDb

Public Class WebForm3
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
    Dim Con As OleDbConnection
    Dim cmd As New OleDbCommand
    Dim conString As String = "Data Source=homepc;Initial Catalog=Incident_Tracker;Integrated Security=True"
    Public Sub SubmitIncident()
        Try
            Dim con As New OleDbConnection
            con.ConnectionString = conString
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "INSERT INTO [Incidents] ( [I_ProductName], [I_ProductDescription], I_SubProductName, I_SubProductDescription, IProductID) VALUES (@Product_Name, @Product_Description, @Sub_ProductName, @Sub_ProductDescription, @ProductID)"
            cmd.ExecuteNonQuery()
            con.Close()
            MsgBox("New Incident Submitted")
            con.Close()
            con.Dispose()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
    Protected Sub InsertButton_Click(sender As Object, e As EventArgs) Handles InsertButton.Click
        SubmitIncident()
    End Sub
End Class

0 个答案:

没有答案