Ciao a tutti, io faccio un update di un campo e la cosa strana è che non mi aggiorna il valore tenendo in memoria quello vecchio come mai? ora vi posto il codice:
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
If Session("admin") = "" Then Response.Redirect("index.aspx")
connetti()
If Request.QueryString("id_categoria") <> "" Then
strsql = "Select * From Categorie where id_categoria=" & Request.QueryString("id_categoria")
cmdSql = New OleDbCommand(strsql, conn)
rs = cmdSql.ExecuteReader()
While rs.Read()
If VarType(rs("id_categoria")) <> 1 Then
id_categoria.Text = rs("id_categoria")
End If
If VarType(rs("titolo")) <> 1 Then
titolo.Text = rs("titolo")
End If
If VarType(rs("listino")) <> 1 Then
nomeallegato1.Text = rs("listino")
End If
End While
rs.Close()
conn.Close()
conn = Nothing
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
connetti()
Dim pathAllegato1 As String
Dim allegato1 As String
allegato1 = allegato_1.PostedFile.FileName
If allegato1 <> "" Then
allegato1 = nomeFile(allegato1)
pathAllegato1 = Server.MapPath(".") & "\..\Listini\" & allegato1
allegato_1.PostedFile.SaveAs(pathAllegato1)
End If
If id_categoria.Text = "" Then
strsql = "Insert into Categorie( titolo, listino) Values("
strsql = strsql & "'" & Replace(titolo.Text, "'", "''") & "'"
strsql = strsql & ", '" & Replace(allegato1, "'", "''") & "'"
strsql = strsql & ")"
Else
strsql = "Update Categorie set"
strsql = strsql & " titolo='" & Replace(titolo.Text, "'", "''") & "'"
strsql = strsql & ", listino='" & Replace(allegato1, "'", "''") & "'"
strsql = strsql & " where id_categoria=" & id_categoria.Text
Response.Write(strsql)
Response.End()
End If
cmdSql = New OleDbCommand(strsql, conn)
cmdSql.ExecuteNonQuery()
messaggio.Text = "Operazione effettuata"
Catch ex As Exception
messaggio.Text = "Errore: " & ex.Message() & "
" & strsql
Finally
conn.Close()
End Try
conn.Close()
End Sub
Ed ecco la parte html:
<form id="Form1" method="post" runat="server">
<TABLE width="700" height="500" border="0" align="center" cellPadding="1" cellSpacing="1">
<TBODY>
<TR>
<TD style="WIDTH: 150px" vAlign="top">
<TABLE width="140" border="0" align="center" cellPadding="1" cellSpacing="1" id="Table2">
<TBODY>
<TR>
<TD><div align="center" class="Stile8">Gestione Gruppi</div>
</TD>
</TR>
<TR>
<TD><div align="left">Inserisci Gruppi</div>
</TD>
</TR>
<TR>
<TD><div align="left">Mod/Canc Gruppi</div>
</TD>
</TR>
<TR>
<TD><div align="center" class="Stile8">Gestione Utenti</div>
</TD>
</TR>
<TR>
<TD><div align="left">Inserisci Utenti</div>
</TD>
</TR>
<TR>
<TD><div align="left">Mod/Canc Utenti</div>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
<TD vAlign="top" align="center">
<span class="Stile5"><span class="Stile9">GESTIONE GRUPPI</span>
</span>
<div align="center" class="Stile6">
<asp:label id="messaggio" runat="server"></asp:label></div>
<TABLE id="Table3" cellSpacing="1" cellPadding="1" width="387" border="0">
<TR>
<TD><div align="left" class="contenuto">Nome Gruppo:</div>
</TD>
<TD>
<asp:TextBox id="titolo" runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD><div align="left" class="contenuto">File Listino:
<asp:label id="nomeallegato1" runat="server"></asp:label></div>
</TD>
<TD><INPUT id="allegato_1" type="file" runat="server"></TD>
</TR>
<TR>
<TD align="center" colSpan="2"><asp:button id="Button1" runat="server" Text="Salva"></asp:button><asp:textbox id="id_categoria" runat="server" Visible="False"></asp:textbox></TD>
</TR>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
</form>