好吧,我已經紮根於以前提出的問題,改變了我的代碼三四次,仍然無法得到我正在向我的表格中插入數據的表單。尋找有用的建議。對於一個或多個所需參數沒有給出值。 vb
表單代碼:
<div>
<table align="center" width="200px" cellpadding="5px">
<tr><td width="50px">Season:</td><td width="150px">
<asp:DropDownList name="Season" ID="ddlSeason" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="Season" DataValueField="Season">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SeasonConnectionString %>" ProviderName="<%$ ConnectionStrings:SeasonConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [T_Season] ORDER BY [Season]"></asp:SqlDataSource>
</td></tr>
<tr><td>Game: </td><td>
<asp:DropDownList name="Game" ID="ddlGameNumber" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="Game" DataValueField="Game">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:GameNumberConnectionString %>" ProviderName="<%$ ConnectionStrings:GameNumberConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [T_GameNumbers] ORDER BY [Game]"></asp:SqlDataSource>
</td></tr>
<tr><td>Team: </td><td>
<asp:DropDownList name="Team" ID="ddlTeam" runat="server" Height="16px" Width="122px" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="Team" DataValueField="Team">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:TeamConnectionString %>" ProviderName="<%$ ConnectionStrings:TeamConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCT * FROM [T_Teams] ORDER BY [Team]"></asp:SqlDataSource>
</td></tr>
<tr><td>Player: </td><td>
<asp:DropDownList name="Player" ID="ddlPlayer" runat="server" Height="16px" Width="121px" AutoPostBack="True" DataSourceID="SqlDataSource4" DataTextField="Player" DataValueField="Player">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:PlayerConnectionString %>" ProviderName="<%$ ConnectionStrings:PlayerConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCT [Team], [Player] FROM [T_Passing] WHERE (([Season] = ?) AND ([Team] = ?)) ORDER BY [Player]">
<SelectParameters>
<asp:ControlParameter ControlID="ddlSeason" Name="Season" PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlTeam" Name="Team" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td></tr>
<tr><td>Atts: </td><td>
<asp:DropDownList name="Atts" ID="ddlAtts" runat="server" DataSourceID="SqlDataSource5" DataTextField="Game" DataValueField="Game">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:AttsConnectionString %>" ProviderName="<%$ ConnectionStrings:AttsConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [T_Atts] ORDER BY [Game]"></asp:SqlDataSource>
</td></tr>
<tr><td>Comps: </td><td>
<asp:DropDownList name="Comps" ID="ddlComps" runat="server" DataSourceID="SqlDataSource6" DataTextField="Comps" DataValueField="Comps">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:CompletionsConnectionString %>" ProviderName="<%$ ConnectionStrings:CompletionsConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [T_Comps] ORDER BY [Comps]"></asp:SqlDataSource>
</td></tr>
<tr><td>Yards: </td><td>
<asp:TextBox name="Yards" ID="txtYards" runat="server" Width="68px" Text="0"></asp:TextBox>
</td></tr>
<tr><td>TDs: </td><td>
<asp:DropDownList name="TDs" ID="ddlTDs" runat="server" DataSourceID="SqlDataSource7" DataTextField="TDs" DataValueField="TDs">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:TDConnectionString %>" ProviderName="<%$ ConnectionStrings:TDConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [T_TDs] ORDER BY [TDs]"></asp:SqlDataSource>
</td></tr>
<tr><td>Ints: </td><td>
<asp:DropDownList name="Ints" ID="ddlInts" runat="server" DataSourceID="SqlDataSource8" DataTextField="Ints" DataValueField="Ints">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource8" runat="server" ConnectionString="<%$ ConnectionStrings:IntsConnectionString %>" ProviderName="<%$ ConnectionStrings:IntsConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [T_Ints] ORDER BY [Ints]"></asp:SqlDataSource>
</td></tr>
<tr><td>Long: </td><td>
<asp:TextBox name="Longest" ID="txtLongest" runat="server" Width="67px" Text="0"></asp:TextBox>
</td></tr>
<tr><td colspan="2" align="center">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td></tr>
</table>
</div>
代碼背後:
Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim season As String = Request.Form("Season")
Dim game As String = Request.Form("Game")
Dim team As String = Request.Form("Team")
Dim player As String = Request.Form("Player")
Dim atts As String = Request.Form("Atts")
Dim comps As String = Request.Form("Comps")
Dim yards As String = Request.Form("Yards")
Dim tds As String = Request.Form("TDs")
Dim ints As String = Request.Form("Ints")
Dim longest As String = Request.Form("Longest")
Dim objConnection As OleDbConnection = Nothing
Dim objcmd As OleDbCommand = Nothing
Dim sqlString As String
Dim dbconn As OleDbConnection = Nothing
dbconn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Server.MapPath("~/App_Data/TCFLStatistics.accdb"))
dbconn.Open()
sqlString = "Insert into T_Passing (Season, Game, Team, Player, Atts, Comps, Yards, TDs, INTs, Longest) Values (?,?,?,?,?,?,?,?,?,?)"
objcmd = New OleDbCommand(sqlString, dbconn)
objcmd.Parameters.AddWithValue("@Season", ddlSeason.SelectedValue.ToString)
objcmd.Parameters.AddWithValue("@Game", ddlGameNumber.SelectedValue.ToString)
objcmd.Parameters.AddWithValue("@Team", ddlTeam.SelectedValue.ToString)
objcmd.Parameters.AddWithValue("@Player", ddlPlayer.SelectedValue.ToString)
objcmd.Parameters.AddWithValue("@Atts", ddlAtts.SelectedValue.ToString)
objcmd.Parameters.AddWithValue("@Comps", ddlComps.SelectedValue.ToString)
objcmd.Parameters.AddWithValue("@Yards", txtYards.Text)
objcmd.Parameters.AddWithValue("@TDs", ddlTDs.SelectedValue.ToString)
objcmd.Parameters.AddWithValue("@INTs", ddlInts.SelectedValue.ToString)
objcmd.Parameters.AddWithValue("@Longest", txtLongest.Text)
objcmd.ExecuteNonQuery()
dbconn.Close()
MsgBox("Record submitted successfully!")
End Sub
剛剛嘗試過你的建議和沒有骰子... – championcyclones
好吧,我提供的唯一的其他事情是檢查你的參數(當前所有字符串)的數據類型與數據庫字段的數據類型。 –