473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

like avoiding to always insert the same elements

I am making the pages asp of one library on-linens with visual study 2003. I
have created the datagrid, the subroutine UpdateCommand. .now I want to
avoid to always insert the same element. .someone says me like making? I
would have to make a IF. .but like? In order to help to understand you, I
put you the code vb and that asp of mine web form!

Imports System.Data.SqlClient

Public Class WebForm9

Inherits System.Web.UI.Page

Dim conDatabase_BIBLIOTECA As SqlConnection

Dim cmdSql As SqlCommand

Protected WithEvents dgrdLIBRI As System.Web.UI.WebControls.DataGrid

Dim strSql As String

#Region " Codice generato da Progettazione Web Form "

'Chiamata richiesta da Progettazione Web Form.

<System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()

End Sub

'NOTA: la seguente dichiarazione è richiesta da Progettazione Web Form.

'Non spostarla o rimuoverla.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: questa chiamata al metodo è richiesta da Progettazione Web Form.

'Non modificarla nell'editor del codice.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Inserire qui il codice utente necessario per inizializzare la pagina

conDatabase_BIBLIOTECA = New SqlConnection("Server=.;database=Database
BIBLIOTECA;Integrated Security=SSPP;Trusted_Connection=Yes")

If Not IsPostBack Then

BindDataGrid()

End If

End Sub

Sub BindDataGrid()

cmdSql = New SqlCommand("SELECT * FROM LIBRI", conDatabase_BIBLIOTECA)

conDatabase_BIBLIOTECA.Open()

dgrdLIBRI.DataSource = cmdSql.ExecuteReader

dgrdLIBRI.DataBind()

conDatabase_BIBLIOTECA.Close()

End Sub

Sub dgrdLIBRI_EditCommand(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)

dgrdLIBRI.EditItemIndex = e.Item.ItemIndex

BindDataGrid()

End Sub

Sub dgrdLIBRI_UpdateCommand(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)

Dim intId_libri As Integer

Dim txtCodice_Rfid As TextBox

Dim TxtTitolo_del_libro As TextBox

Dim strCodice_Rfid As String

Dim strTitolo_del_libro As String

intId_libri = dgrdLIBRI.DataKeys(e.Item.ItemIndex)

txtCodice_Rfid = e.Item.Cells(1).Controls(0)

TxtTitolo_del_libro = e.Item.Cells(2).Controls(0)

strCodice_Rfid = txtCodice_Rfid.Text

strTitolo_del_libro = TxtTitolo_del_libro.Text

strSql = "Update LIBRI Set Codice_Rfid=@Codice_Rfid, " &
"Titolo_del_libro=@Titolo_del_libro Where Id_libri=@Id_libri"

cmdSql = New SqlCommand(strSql, conDatabase_BIBLIOTECA)

cmdSql.Parameters.Add("@Codice_Rfid", strCodice_Rfid)

cmdSql.Parameters.Add("@Titolo_del_libro", strTitolo_del_libro)

cmdSql.Parameters.Add("@Id_libri", intId_libri)

conDatabase_BIBLIOTECA.Open()

cmdSql.ExecuteNonQuery()

conDatabase_BIBLIOTECA.Close()

dgrdLIBRI.EditItemIndex = -1

BindDataGrid()

End Sub

Sub dgrdLIBRI_CancelCommand(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)

dgrdLIBRI.EditItemIndex = -1

BindDataGrid()

End Sub

End Class


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="LIBRI3.aspx.vb"
Inherits="Biblioteca.WebForm9"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<title>WebForm9</title>

<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">

<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">

<meta name="vs_defaultClientScript" content="JavaScript">

<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">

</HEAD>

<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">

<asp:DataGrid id="dgrdLIBRI" OnEditCommand="dgrdLIBRI_EditCommand"
OnUpdateCommand="dgrdLIBRI_UpdateCommand"

OnCancelCommand="dgrdLIBRI_CancelCommand" DataKeyField="Id_libri"
AutoGenerateColumns="False"

CellPadding="10" HeaderStyle-BackColor="Salmon" style="Z-INDEX: 101; LEFT:
360px; POSITION: absolute; TOP: 120px"

runat="server">

<Columns>

<asp:BoundColumn HeaderText="ID Libri" DataField="Id_libri" ReadOnly="True"
visible="False" />

<asp:BoundColumn HeaderText="Codice Rfid" DataField="Codice_Rfid" />

<asp:BoundColumn HeaderText="Titolo del libro" DataField="Titolo_del_libro"
/>

<asp:EditCommandColumn EditText="Edit!" UpdateText="Update!"
CancelText="Cancel!" />

</Columns>

</asp:DataGrid>

</form>

</body>

</HTML>


Nov 13 '06 #1
0 1340

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steffen Beyer | last post by:
Hi, my XSLT processes input documents which use various namespaces. Short example: XML input: <news:foo xmlns:news="http://some.example/news"/>
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
7
by: Alan Holloway | last post by:
Hi all, Firstly thanks for your golden insight on my earlier post re bitwise operations. I now have another question! I've just been reading the excellent Peter van der Linden excerpt ...
1
by: tinie | last post by:
I encounter problems in inserting elements in a 2d vector. For example I want to insert 99 in v, how would I do it? What I have is this code: #include <iostream> #include <iomanip> #include...
6
by: reppisch | last post by:
Hi Ng, I have a multiset for keeping elements sorted in a container but key values may also be equal. Is there any guaranteed traversal order within the duplicate keys of a multimap? When...
30
by: David Mathog | last post by:
Every so often I find a need to move data in or out of functions which are not called directly. For instance, alarm handlers or the compare function used by qsort. In these cases there is no...
1
by: subramanian100in | last post by:
Suppose I have vector<intvi; deque<intdi; list<intli; Suppose all of these containers have some elements. Suppose 'v_iter' is an iterator pointing to some element in 'vi'. Suppose 'v_beg'...
2
by: subramanian100in | last post by:
In ISO/IEC 14882:2003 document, in the section '23.2.1.3 deque modifiers', the following is mentioned: iterator insert(iterator position, const T& x); void insert(iterator position, size_type...
5
by: John Doe | last post by:
Hi, I have a static array of struct defined like this : CViewMgr::ViewInfo g_ViewInfo = { { EMainView, ECreateOnce, IDR_MAINFRAME, RUNTIME_CLASS(CMainView), NULL,0, 0 }, {...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.