Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá,
sou iniciante na plataforma .net e estou tentando criar um pequeno formulário que inserir o Nome, Sobre Nome e email é enviado para uma pequena base de dados em sql, segue os dados para analise!
Obs.: peço que ao responder explique o motivo do erro.
:rolleyes: Obrigado.
Página default.aspx
<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void inserir (object source, EventArgs e){
SqlDataSource.Insert();
}
protected void Page_Load(object sender, EventArgs e)
{
}
</script>
<html>
<head runat="server">
<title>Inserindo dados com SQL</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:infratelecomConnectionString %>"
SelectCommand="SELECT [nome], [sobrenome], [email] FROM [Telefonia]">
</asp:SqlDataSource>
<br />
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource"
DataTextField="nome"
DataValueField="sobrenome" Height="20px" Width="167px">
</asp:DropDownList>
<br />
<asp:Label ID="Label1" runat="server" Text="Nome: "></asp:Label>
<br />
<asp:TextBox ID="Nome" runat="server">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="Nome" ErrorMessage="Digite seu nome!"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label2" runat="server" Text="Sobre Nome:"></asp:Label>
<br />
<asp:TextBox ID="sobrenome" runat="server">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="sobrenome" ErrorMessage="Digite seu sobre nome!"></asp:RequiredFieldValidator>
<br />
<asp:Label ID="Label3" runat="server" Text="E-mail:"></asp:Label>
<br />
<asp:TextBox ID="email" runat="server">
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="email" ErrorMessage="Digite seu e-mail!" Visible="False"></asp:RequiredFieldValidator>
<br /> </div>
</form>
</body>
</html>
Base SQL
create database infratelecom
Create table Telefonia (
nome varchar(50) not null primary key,
sobrenome varchar(50) not null,
email varchar(80) not null,
)
Erro que apresenta
Inserting is not supported by data source 'SqlDataSource' unless InsertCommand is specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NotSupportedException: Inserting is not supported by data source 'SqlDataSource' unless InsertCommand is specified.
Source Error:
Line 4: <script runat="server">
Line 5: private void inserir (object source, EventArgs e){
Line 6: SqlDataSource.Insert();
Line 7: }
Line 8:
Carregando comentários...