Я использую приведенный ниже код, чтобы клиент мог вставить новый вопрос в таблицу. Я использую представление подробностей, чтобы разрешить вставку данных, я создал хранимую процедуру в моей базе данных SQL, которую нужно уволить, и позволить вставлять данные в базу данных, любая идея, почему программа не добавляет информацию в стол,SQLDataSource с использованием хранимой процедуры для вставки
<asp:DetailsView ID="DetailsView1" runat="server" DefaultMode="Insert"
AutoGenerateRows="False" DataSourceID="Question" DataKeyNames="questionID">
<CommandRowStyle BackColor="#D1DDF1" />
<EditRowStyle BackColor="#F1F1F2" />
<FieldHeaderStyle BackColor="#546E96" BorderColor="#465767" ForeColor="White" />
<Fields>
<asp:TemplateField HeaderText="QuestionNo" SortExpression="QuestionNo">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("QuestionNo") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:ListBox ID="ListBox2" runat="server" DataSourceID="SqlAvailableQuestionNumbers"
DataTextField="questionno" DataValueField="questionno" Rows="1" SelectedValue='<%# Bind("QuestionNo") %>'
Width="75px"></asp:ListBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("QuestionNo") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="QuestionType" SortExpression="QuestionType">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("QuestionType") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:ListBox ID="ListBox3" runat="server" DataSourceID="LinqGetQuestionTypes" DataTextField="name"
DataValueField="questionTypeID" Rows="1" SelectedValue='<%# Bind("QuestionType") %>'>
</asp:ListBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("QuestionType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="question" SortExpression="question">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("question") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("question") %>' Rows="6"
TextMode="MultiLine"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("question") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
</Fields>
<HeaderStyle BackColor="#546E96" ForeColor="White" />
<RowStyle BackColor="#F1F1F2" />
</asp:DetailsView>
<asp:DropShadowExtender ID="DetailsView1_DropShadowExtender" runat="server"
Enabled="True" TargetControlID="DetailsView1">
</asp:DropShadowExtender>
<asp:SqlDataSource ID="Question" runat="server"
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
InsertCommand="insertNewQuestionSub" InsertCommandType="StoredProcedure" SelectCommand="select
[QuestionType]
,[QuestionNo]
,[question]
from Questions">
<InsertParameters>
<asp:Parameter Name="QuestionType" Type="Int32" />
<asp:Parameter Name="QuestionNo" Type="Int32" />
<asp:Parameter Name="question" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
хранимая процедура
ALTER PROCEDURE [dbo].[insertQuestion]
-- Add the parameters for the stored procedure here
@QuestionType int,
@QuestionNo int,
@question nvarchar
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO Questions (QuestionType,QuestionNo,question)
VALUES (@QuestionType,@QuestionNo,@question))
END
у вас есть ошибки? в коде asp.net или в sql при попытке выполнить SP вручную? –
У меня нет ошибок, код просто добавляет нулевые строки в таблицу – user3086751
Вы видите, что sp выполняется при запуске sql-профайлера? Я настоятельно рекомендую поместить SQL-запрос в код позади. Множество причин для разделения отображения и бизнес-логики, и его легче отлаживать, вставив точку останова – Feuerwehrmann