Я пытаюсь связать мой вид формы asp.net с базой данных MySQL, но без успеха.
Взгляните на мой код и сообщите мне, где моя ошибка:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ImageID"
DataSourceID="SqlDataSource1" EnableModelValidation="True">
<EditItemTemplate>
ImageID:
<asp:Label ID="ImageIDLabel1" runat="server" Text='<%# Eval("ImageID") %>' />
<br />
Title:
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Title:
<asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title") %>' />
<br />
Description:
<asp:TextBox ID="DescriptionTextBox" runat="server"
Text='<%# Bind("Description") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
ImageID:
<asp:Label ID="ImageIDLabel" runat="server" Text='<%# Eval("ImageID") %>' />
<br />
Title:
<asp:Label ID="TitleLabel" runat="server" Text='<%# Bind("Title") %>' />
<br />
Description:
<asp:Label ID="DescriptionLabel" runat="server"
Text='<%# Bind("Description") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:cmsConnectionString %>"
InsertCommand="INSERT INTO [tbimages] ([ImageID], [Title], [Description]) VALUES (ImageID, Title, Description)"
ProviderName="<%$ ConnectionStrings:cmsConnectionString.ProviderName %>"
SelectCommand="SELECT ImageID, Title, Description FROM tbimages"
UpdateCommand="UPDATE [tbimages] SET [Title] = ?, [Description] = ? WHERE [ImageID] = ?">
<InsertParameters>
<asp:Parameter Name="ImageID" Type="Int64" />
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Description" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="ImageID" Type="Int64" />
</UpdateParameters>
</asp:SqlDataSource>
Я уже определяю свою строку подключения в веб-конфигурации:
<connectionStrings>
<add name="cmsConnectionString" connectionString="server=localhost;User Id=root;password=123;database=cms" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
Пожалуйста, если у вас есть идея решить эту проблему, дайте мне знать.
Возможно, вы захотите изменить команду вставки так:
InsertCommand="INSERT INTO [tbimages] ([ImageID], [Title], [Description]) VALUES (? , ? , ?)"
ОБНОВЛЕНО:
InsertCommand="INSERT INTO [tbimages] ([ImageID], [Title], [Description])
VALUES (?ImageID , ?Title , ?Description)"
проверьте определение команды вставки вашего источника данных. См. Также: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.insertcommand.aspx