Pijama® 0 Denunciar post Postado Agosto 26, 2008 Pessoal, bom dia!!! antes eu não conseguia colocar os dados pra dentro do BD, agora que eu consegui, ele vai duplicado, vai o codigo ai, pra ver se conseguem me ajudar ou me dizer o porque de estar duplicando ao clicar no botão. Partial Class cadimovelanun Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click MyInsertMethod() datacadastro.Text = Now.Date.ToShortDateString() End Sub Function MyInsertMethod() As Integer Dim connectionString As String = "server='(local)'; user id='sa'; password='12345'; database='joaobarro'" Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString) Dim queryString As String = "INSERT INTO [cad.imovelanunciante] ([tipo], [endereco], [bairro], [cidade], [descricao], [dormitorios], [suites], [banheiros], [areautil], [destaque], [plano], [foto0], [foto01], [foto02], [foto03], [foto04], [fo" & _ "to05], [datacadastro], [anunciante]) VALUES ('" & Me.tipo.Text & "','" & Me.endereco.Text & "','" & Me.bairro.Text & "','" & Me.Cidades.Text & "','" & Me.descricao.Text & "','" & Me.dormitorios.Text & "','" & Me.suites.Text & "','" & Me.banheiros.Text & "','" & Me.areautil.Text & "','" & Me.destaque.Text & "','" & Me.planos.Text & "','" & Me.foto0.Text & "','" & Me.foto01.Text & "','" & Me.foto02.Text & "','" & Me.foto03.Text & "','" & Me.foto04.Text & "','" & Me.foto05.Text & "','" & Me.datacadastro.Text & "','" & Me.anunciante.Text & "')" Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection Dim rowsAffected As Integer = 0 dbConnection.Open() Try rowsAffected = dbCommand.ExecuteNonQuery Finally dbConnection.Close() End Try Return rowsAffected End Function Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles plano.SelectedIndexChanged End Sub End Class <%@ Page Language="VB" AutoEventWireup="false" CodeFile="cadimovelanun.aspx.vb" Inherits="cadimovelanun" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>..::João de Barro::.. | Cadastro Imovel</title> </head> <body> <form id="form1" runat="server"> <table style="WIDTH: 562px; HEIGHT: 313px"> <tbody> <tr> <td> <table style="WIDTH: 557px; HEIGHT: 46px"> <tbody> <tr> <td> <font face="tahoma" size="2">Plano: <br /> <asp:DropDownList id="plano" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="92px" AutoPostBack="True" DataSourceID="SqlDataSource10" DataTextField="planos" DataValueField="planos" CausesValidation="True"> </asp:DropDownList> </font></td> <td> <font face="tahoma" size="2">Cidade: <br /> <asp:DropDownList id="Cidades" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="138px" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="cidade" DataValueField="cidade"> </asp:DropDownList> </font></td> <td> <font face="tahoma" size="2">Estado: <br /> <asp:DropDownList id="estado" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="132px" AutoPostBack="True" DataSourceID="SqlDataSource2" DataTextField="estado" DataValueField="estado"> </asp:DropDownList> </font></td> <td> <font face="tahoma" size="2">Bairro: <br /> <asp:TextBox id="bairro" runat="server" Width="114px"></asp:TextBox> </font></td> </tr> </tbody> </table> <table> <tbody> <tr> <td> <font face="tahoma" size="2">Dormitórios: <br /> <asp:DropDownList id="dormitorios" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="75px" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="dormitorios" DataValueField="dormitorios"></asp:DropDownList> </font></td> <td> <font face="tahoma" size="2">Suites: <br /> <asp:DropDownList id="suites" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="75px" AutoPostBack="True" DataSourceID="SqlDataSource4" DataTextField="suites" DataValueField="suites"></asp:DropDownList> </font></td> <td> <font face="tahoma" size="2">Banheiros: <br /> <asp:DropDownList id="banheiros" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="75px" AutoPostBack="True" DataSourceID="SqlDataSource5" DataTextField="banheiros" DataValueField="banheiros"></asp:DropDownList> </font></td> <td> <font face="tahoma" size="2">Area Útil (m²): <br /> <asp:TextBox id="areautil" runat="server" Width="136px"></asp:TextBox> </font></td> <td> <font face="tahoma" size="2">Plano Anuncio (Dias): <br /> <asp:DropDownList id="planos" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="132px" AutoPostBack="True" DataSourceID="SqlDataSource6" DataTextField="planos" DataValueField="planos"></asp:DropDownList> </font></td></tr> </tbody> </table> <table> <tbody> <tr> <td style="height: 80px"> <font face="tahoma" size="2">Destaque: <br /> <asp:DropDownList id="destaque" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="138px" AutoPostBack="True" DataSourceID="SqlDataSource7" DataTextField="destaque" DataValueField="destaque"></asp:DropDownList> </font></td> <td style="height: 80px"> <font face="tahoma" size="2">Data Cadastro: <br /> <asp:TextBox id="datacadastro" runat="server" Width="110px"></asp:TextBox> </font></td> <td style="height: 80px"> <font face="tahoma" size="2">Codigo Anunciante: <br /> <asp:DropDownList id="anunciante" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" Width="138px" AutoPostBack="True" DataSourceID="SqlDataSource8" DataTextField="codigo" DataValueField="codigo"></asp:DropDownList> </font></td> <td style="height: 80px"> <font face="tahoma" size="2">Tipo de Negócio: <br /> <asp:DropDownList id="tipo" runat="server" AppendDataBoundItems="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True" DataSourceID="SqlDataSource9" DataTextField="tiponegocio" DataValueField="tiponegocio"></asp:DropDownList> </font></td> </tr> </tbody> </table> <table> <tbody> <tr> <td> <font face="tahoma" size="2">Foto 01:<font color="red" size="1">(Somente o Nome)</font> <br /> <asp:TextBox id="foto0" runat="server" Width="140px"></asp:TextBox> </font></td> <td> <font face="tahoma" size="2">Foto 02:<font color="red" size="1">(Somente o Nome)</font> <br /> <asp:TextBox id="foto01" runat="server" Width="140px"></asp:TextBox> </font></td> <td> <font face="tahoma" size="2">Foto 03:<font color="red" size="1">(Somente o Nome)</font> <br /> <asp:TextBox id="foto02" runat="server" Width="140px"></asp:TextBox> </font></td> </tr> <tr> <td> <font face="tahoma" size="2">Foto 04:<font color="red" size="1">(Somente o Nome)</font> <br /> <asp:TextBox id="foto03" runat="server" Width="140px"></asp:TextBox> </font></td> <td> <font face="tahoma" size="2">Foto 05:<font color="red" size="1">(Somente o Nome)</font> <br /> <asp:TextBox id="foto04" runat="server" Width="140px"></asp:TextBox> </font></td> <td> <font face="tahoma" size="2">Foto 06:<font color="red" size="1">(Somente o Nome)</font> <br /> <asp:TextBox id="foto05" runat="server" Width="140px"></asp:TextBox> </font></td> </tr> </tbody> </table> <table style="WIDTH: 554px; HEIGHT: 62px"> <tbody> <tr> <td> <font face="tahoma" size="2">Descrição: <br /> <asp:TextBox id="descricao" runat="server" Width="554px" TextMode="MultiLine" Height="135px"></asp:TextBox> </font></td> </tr> </tbody> </table> <table> <tbody> <tr> <td> <font face="tahoma" size="2">Endereço: <font color="red" size="1">Preenchimento Obrigatório, favor preencher o Endereço corretamente.</font> <br /> <asp:TextBox id="endereco" runat="server" Width="550px"></asp:TextBox> </font></td> </tr> </tbody> </table> <table> <tbody> <tr> <td align="middle"> <asp:Button id="Button2" onclick="Button1_Click" runat="server" Width="550px" Text="Cadastrar Imovel"></asp:Button> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [cidade] FROM [cidades]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [estado] FROM [estados]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [dormitorios] FROM [dormitorios]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [suites] FROM [suites]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [banheiros] FROM [banheiros]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [planos] FROM [planos]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource7" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [destaque] FROM [destaque]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource8" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [codigo] FROM [anunciante]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource9" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [tiponegocio] FROM [tiponegocio]"></asp:SqlDataSource> <asp:SqlDataSource ID="SqlDataSource10" runat="server" ConnectionString="<%$ ConnectionStrings:joaobarroConnectionString %>" SelectCommand="SELECT [planos] FROM [planos]"></asp:SqlDataSource> </form> </body> </html> Compartilhar este post Link para o post Compartilhar em outros sites
quintelab 91 Denunciar post Postado Agosto 26, 2008 Sem floods!! http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif De uma olhada neste tópico, acha que o seu problema é o mesmo: http://forum.imasters.com.br/index.php?showtopic=300696 Abraços... Compartilhar este post Link para o post Compartilhar em outros sites