Graba registros duplicados
Publicado por Angel (2 intervenciones) el 07/06/2007 11:33:53
Hola a todos,
Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
Dim row As GridViewRow = GridView1.Rows(e.NewSelectedIndex)
Dim sProveedor As String
Dim ProData As Data.Common.DbProviderFactory
Dim oDB As DbConnection = Nothing
Dim cmDB As DbCommand = Nothing
Dim sCadenaConexion As String
Dim SQL As String
sProveedor = "System.Data.SqlClient"
sCadenaConexion = "Data Source=DISTEL04\SQLEXPRESS;Initial Catalog=WEB;Integrated Security=True"
ProData = DbProviderFactories.GetFactory(sProveedor)
oDB = ProData.CreateConnection()
cmDB = ProData.CreateCommand()
oDB.ConnectionString = sCadenaConexion
Try
SQL = "INSERT INTO TMPPed (IDUsu, IDProd, Descr, IDAlm, Cant, FAdd) values ('" & Request.Cookies("QALI").Value & "', '" & row.Cells(5).Text & "','" & row.Cells(4).Text & "','" & Request.Cookies("QALM").Value & "', 1 , GETDATE()" & " )"
oDB.Open()
cmDB.Connection = oDB
cmDB.CommandText = SQL
cmDB.ExecuteNonQuery() ' actualizo el registro
oDB.Close()
Catch except As Exception
Response.Write("<p align=center style='font-family:verdana; font-size:7pt; color:red;'>" & _
"<b>ERROR: " & except.Message & "</b></p>")
Response.End()
End Try
e.Cancel = True
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
</head>
<body background="topFrames_archivos/Fondo oficina 1.jpg">
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="2" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None" Style="z-index: 100; left: 40px; position: absolute;
top: 56px" PageSize="25" CaptionAlign="Top" DataKeyNames="XFAMILIA_ID,N351MARCA,N351MODELO" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" Height="431px">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" Font-Size="X-Small" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Size="X-Small" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ButtonType="Image" SelectImageUrl="~/Distel_archivos/topFrames_archivos/carrito 1 peq.jpg"
ShowSelectButton="True" SelectText="Añadir al carrito" />
<asp:BoundField DataField="XFAMILIA_ID" HeaderText="FAMILIA" ReadOnly="True"
SortExpression="XFAMILIA_ID" >
<ItemStyle Font-Size=X-Small/>
</asp:BoundField>
<asp:BoundField DataField="N351MARCA" HeaderText="MARCA" ReadOnly="True"
SortExpression="N351MARCA" >
<ItemStyle Font-Size=X-Small/>
</asp:BoundField>
<asp:BoundField DataField="N351MODELO" HeaderText="MODELO" ReadOnly="True"
SortExpression="N351MODELO" >
<ItemStyle Font-Size=X-Small/>
</asp:BoundField>
<asp:BoundField DataField="XDESCRIPCION" HeaderText="DESCRIPCION" ReadOnly="True"
SortExpression="XDESCRIPCION" >
<ItemStyle Font-Size="X-Small" />
</asp:BoundField>
<asp:BoundField DataField="XARTICULO_ID" HeaderText="ARTICULO" ReadOnly="True"
SortExpression="XARTICULO_ID" >
<ItemStyle Font-Size="X-Small" />
</asp:BoundField>
<asp:BoundField DataField="PVP" HeaderText="P.CESION" ReadOnly="True" SortExpression="PVP" >
<ItemStyle Font-Size="X-Small" HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="XEMPRESA_ID" HeaderText="XEMPRESA_ID" ReadOnly="True" Visible=False
SortExpression="XEMPRESA_ID" />
</Columns>
</asp:GridView>
<span style="font-size: 7pt; color: #666666; font-family: Verdana">Seleccione la familia de productos a trabajar:</span>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="XDESCRIPCION" DataValueField="XFAMILIA_ID" Style="z-index: 101;
left: 48px; position: absolute; top: 33px" Width="135px" AutoPostBack="True" Font-Size="X-Small" >
</asp:DropDownList>
Productos seleccionados:
<asp:TextBox ID="TotSel" runat="server" ReadOnly="True" Style="z-index: 105; left: 457px;
position: absolute; top: 11px" Width="56px"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server" BorderStyle="Ridge" BorderWidth="1px"
Height="40px" ImageUrl="~/Distel_archivos/topFrames_archivos/carrito 1.jpg" OnClick="ImageButton2_Click"
Style="z-index: 103; left: 658px; position: absolute; top: 1px" ToolTip="Ver cesta"
Width="40px" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Clientes %>"
ProviderName="<%$ ConnectionStrings:Clientes.ProviderName %>" SelectCommand="SELECT XEMPRESA_ID, XFAMILIA_ID, XDESCRIPCION FROM PL_FAMILIAS WHERE (XEMPRESA_ID = 'DIS')">
</asp:SqlDataSource>
<asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" Style="z-index: 104;
left: 605px; position: absolute; top: 1px" BorderStyle="Ridge" BorderWidth="1px" Height="40px" ImageUrl="~/Distel_archivos/topFrames_archivos/notas 1.jpg" Width="39px" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Stock %>"
ProviderName="<%$ ConnectionStrings:Stock.ProviderName %>"
SelectCommand= "SELECT PL_ARTICULOS.XEMPRESA_ID, PL_ARTICULOS.XIVA_ID, PL_ARTICULOS.XFAMILIA_ID, PL_ARTICULOS.N351MARCA, PL_ARTICULOS.N351MODELO, PL_ARTICULOS.XARTICULO_ID, PL_ARTICULOS.XDESCRIPCION, DOUBLE(CHAR(PL_ARTICULOS.XPREC_ULT_ENTRA)) AS PVP, PL_ARTICULOS.XPART_ARANCEL FROM PL_ARTICULOS WHERE (PL_ARTICULOS.XEMPRESA_ID = ? AND PL_ARTICULOS.XIVA_ID = ? AND PL_ARTICULOS.XFAMILIA_ID = ?) ORDER BY PL_ARTICULOS.N351MARCA, PL_ARTICULOS.N351MODELO, PL_ARTICULOS.XDESCRIPCION">
<SelectParameters>
<asp:Parameter DefaultValue="DIS" Name="XEMPRESA_ID" Type="String" />
<asp:SessionParameter SessionField="IVA" Name= "XIVA_ID" Type=String />
<asp:FormParameter FormField="DropDownList1" NAME="XFAMILIA_ID" DefaultValue ="PREP" Type =string />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
Protected Sub GridView1_SelectedIndexChanging(ByVal sender As Object, ByVal e As GridViewSelectEventArgs)
Dim row As GridViewRow = GridView1.Rows(e.NewSelectedIndex)
Dim sProveedor As String
Dim ProData As Data.Common.DbProviderFactory
Dim oDB As DbConnection = Nothing
Dim cmDB As DbCommand = Nothing
Dim sCadenaConexion As String
Dim SQL As String
sProveedor = "System.Data.SqlClient"
sCadenaConexion = "Data Source=DISTEL04\SQLEXPRESS;Initial Catalog=WEB;Integrated Security=True"
ProData = DbProviderFactories.GetFactory(sProveedor)
oDB = ProData.CreateConnection()
cmDB = ProData.CreateCommand()
oDB.ConnectionString = sCadenaConexion
Try
SQL = "INSERT INTO TMPPed (IDUsu, IDProd, Descr, IDAlm, Cant, FAdd) values ('" & Request.Cookies("QALI").Value & "', '" & row.Cells(5).Text & "','" & row.Cells(4).Text & "','" & Request.Cookies("QALM").Value & "', 1 , GETDATE()" & " )"
oDB.Open()
cmDB.Connection = oDB
cmDB.CommandText = SQL
cmDB.ExecuteNonQuery() ' actualizo el registro
oDB.Close()
Catch except As Exception
Response.Write("<p align=center style='font-family:verdana; font-size:7pt; color:red;'>" & _
"<b>ERROR: " & except.Message & "</b></p>")
Response.End()
End Try
e.Cancel = True
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
</head>
<body background="topFrames_archivos/Fondo oficina 1.jpg">
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="2" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None" Style="z-index: 100; left: 40px; position: absolute;
top: 56px" PageSize="25" CaptionAlign="Top" DataKeyNames="XFAMILIA_ID,N351MARCA,N351MODELO" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" Height="431px">
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" Font-Size="X-Small" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Size="X-Small" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ButtonType="Image" SelectImageUrl="~/Distel_archivos/topFrames_archivos/carrito 1 peq.jpg"
ShowSelectButton="True" SelectText="Añadir al carrito" />
<asp:BoundField DataField="XFAMILIA_ID" HeaderText="FAMILIA" ReadOnly="True"
SortExpression="XFAMILIA_ID" >
<ItemStyle Font-Size=X-Small/>
</asp:BoundField>
<asp:BoundField DataField="N351MARCA" HeaderText="MARCA" ReadOnly="True"
SortExpression="N351MARCA" >
<ItemStyle Font-Size=X-Small/>
</asp:BoundField>
<asp:BoundField DataField="N351MODELO" HeaderText="MODELO" ReadOnly="True"
SortExpression="N351MODELO" >
<ItemStyle Font-Size=X-Small/>
</asp:BoundField>
<asp:BoundField DataField="XDESCRIPCION" HeaderText="DESCRIPCION" ReadOnly="True"
SortExpression="XDESCRIPCION" >
<ItemStyle Font-Size="X-Small" />
</asp:BoundField>
<asp:BoundField DataField="XARTICULO_ID" HeaderText="ARTICULO" ReadOnly="True"
SortExpression="XARTICULO_ID" >
<ItemStyle Font-Size="X-Small" />
</asp:BoundField>
<asp:BoundField DataField="PVP" HeaderText="P.CESION" ReadOnly="True" SortExpression="PVP" >
<ItemStyle Font-Size="X-Small" HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="XEMPRESA_ID" HeaderText="XEMPRESA_ID" ReadOnly="True" Visible=False
SortExpression="XEMPRESA_ID" />
</Columns>
</asp:GridView>
<span style="font-size: 7pt; color: #666666; font-family: Verdana">Seleccione la familia de productos a trabajar:</span>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="XDESCRIPCION" DataValueField="XFAMILIA_ID" Style="z-index: 101;
left: 48px; position: absolute; top: 33px" Width="135px" AutoPostBack="True" Font-Size="X-Small" >
</asp:DropDownList>
Productos seleccionados:
<asp:TextBox ID="TotSel" runat="server" ReadOnly="True" Style="z-index: 105; left: 457px;
position: absolute; top: 11px" Width="56px"></asp:TextBox>
<asp:ImageButton ID="ImageButton2" runat="server" BorderStyle="Ridge" BorderWidth="1px"
Height="40px" ImageUrl="~/Distel_archivos/topFrames_archivos/carrito 1.jpg" OnClick="ImageButton2_Click"
Style="z-index: 103; left: 658px; position: absolute; top: 1px" ToolTip="Ver cesta"
Width="40px" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Clientes %>"
ProviderName="<%$ ConnectionStrings:Clientes.ProviderName %>" SelectCommand="SELECT XEMPRESA_ID, XFAMILIA_ID, XDESCRIPCION FROM PL_FAMILIAS WHERE (XEMPRESA_ID = 'DIS')">
</asp:SqlDataSource>
<asp:ImageButton ID="ImageButton1" runat="server" OnClick="ImageButton1_Click" Style="z-index: 104;
left: 605px; position: absolute; top: 1px" BorderStyle="Ridge" BorderWidth="1px" Height="40px" ImageUrl="~/Distel_archivos/topFrames_archivos/notas 1.jpg" Width="39px" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Stock %>"
ProviderName="<%$ ConnectionStrings:Stock.ProviderName %>"
SelectCommand= "SELECT PL_ARTICULOS.XEMPRESA_ID, PL_ARTICULOS.XIVA_ID, PL_ARTICULOS.XFAMILIA_ID, PL_ARTICULOS.N351MARCA, PL_ARTICULOS.N351MODELO, PL_ARTICULOS.XARTICULO_ID, PL_ARTICULOS.XDESCRIPCION, DOUBLE(CHAR(PL_ARTICULOS.XPREC_ULT_ENTRA)) AS PVP, PL_ARTICULOS.XPART_ARANCEL FROM PL_ARTICULOS WHERE (PL_ARTICULOS.XEMPRESA_ID = ? AND PL_ARTICULOS.XIVA_ID = ? AND PL_ARTICULOS.XFAMILIA_ID = ?) ORDER BY PL_ARTICULOS.N351MARCA, PL_ARTICULOS.N351MODELO, PL_ARTICULOS.XDESCRIPCION">
<SelectParameters>
<asp:Parameter DefaultValue="DIS" Name="XEMPRESA_ID" Type="String" />
<asp:SessionParameter SessionField="IVA" Name= "XIVA_ID" Type=String />
<asp:FormParameter FormField="DropDownList1" NAME="XFAMILIA_ID" DefaultValue ="PREP" Type =string />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
Valora esta pregunta
0