|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
[.net]errore
Ciao raga eccomi di nuovo qui con la mia proverbiale ignoranza....
...ho iniziato da poco a lavorare in asp.net e non fa altro che darmi sempre questo errore "Riferimento a un oggetto non impostato su un'istanza di oggetto." Sapete cosa è e che cosa potrei fare? Grazie a tutti |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Jun 2005
Città: Mestre (VE)
Messaggi: 1415
|
Puoi postare il codice?
L' errore è riferito al fatto che forse non c'è congruenza tra i nomi usati e gli oggetti/controlli inseriti ... (anche se dovresti guardare la pagina di debug e lo stack delle operazione per gli errori in asp.net ... le prime righe dell' errore sono puramente descrittive e spesso non dicono niente di più).
__________________
IN WIN 909 / AMD Ryzen 9 3950X / Gigabyte X570 Aorus Xtreme / 4x8gb G.Skill 3200 / Gigabyte Aorus RTX2080Ti Xterme / 2x Gigabyte Aorus NVMe M.2 1Tb / Corsair AX1200i / full liquid EK - Bitspower / circa 160 trattative nel mercatino |
|
|
|
|
|
#3 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
il codice della pagina aspx.vb è il seguente:
Imports System Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Web.UI.HtmlControls Partial Class _Default Inherits System.Web.UI.Page Protected chklst As CheckBoxList Protected WithEvents cmdOk As Button Protected lblResult As Label Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Me.IsPostBack = False Then chklst.Items.Add("C") chklst.Items.Add("C++") chklst.Items.Add("C#") chklst.Items.Add("Visual Basic 6.0") chklst.Items.Add("VB.NET") chklst.Items.Add("Pascal") End If End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click lblResult.Text = "hai scelto:<b>" Dim lstItem As ListItem For Each lstItem In chklst.Items If lstItem.Selected = True Then 'Aggiunge un testo all'etichetta. lblResult.Text &= "<br>" & lstItem.Text End If Next End Sub End Class Di fatto la pagina internet è molto semplice ci sono alcune check box da selezionare e una volta premuto il tasto "OK" sotto dovrebbe semplicemente aprire una lista con le scelte effettuate.Lerrore me lo genera in corrispondenza di "chklst.Items.Add("C")". Non se puo essere utile comunqudi seguito metto anche il codice HTML della pagina aspx corrispondente: <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <!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>Pagina senza titolo</title> </head> <body> <form id="form1" runat="server"> <div accesskey="cmdOK"> <asp:CheckBox ID="CheckBox1" runat="server" Text="C"/><br /> <asp:CheckBox ID="CheckBox2" runat="server" Text="C++"/><br /> <asp:CheckBox ID="CheckBox3" runat="server" Text="C#"/><br /> <asp:CheckBox ID="CheckBox4" runat="server" Text="Visual Basic 6.0"/> <br /> <asp:CheckBox ID="CheckBox5" runat="server" Text="VB.NET"/> <br /> <asp:CheckBox ID="CheckBox6" runat="server" Text="Pascal"/><br /> <br /> <asp:Button ID="Button1" runat="server" Text="Button" /> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div> </form> </body> </html> Grazie |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Jun 2005
Città: Mestre (VE)
Messaggi: 1415
|
Ma non era più semplice fare una unica paginetta (visto che sei ancora agli inizi ed il codice è infimo)?
Codice:
<%@ Page Language="VB" validaterequest="false" %>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
label1.Text = "hai scelto:<b>"
Dim ctl As Control
For Each ctl In Page.Controls(1).Controls
If TypeOf ctl Is CheckBox Then
if CType(ctl, CheckBox).Checked Then
label1.Text += CType(ctl, CheckBox).Text & vbCrLf
End If
End If
Next
label1.Text += "</b>"
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" runat="server" Text="C"/><br />
<asp:CheckBox ID="CheckBox2" runat="server" Text="C++"/><br />
<asp:CheckBox ID="CheckBox3" runat="server" Text="C#"/><br />
<asp:CheckBox ID="CheckBox4" runat="server" Text="Visual Basic 6.0"/>
<br />
<asp:CheckBox ID="CheckBox5" runat="server" Text="VB.NET"/>
<br />
<asp:CheckBox ID="CheckBox6" runat="server" Text="Pascal"/><br />
<br />
<asp:Button ID="Button1" onclick="Button1_Click" runat="server" Text="Button" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Mancavano tutti i riferimenti ai controlli della parte html della pagina ...
__________________
IN WIN 909 / AMD Ryzen 9 3950X / Gigabyte X570 Aorus Xtreme / 4x8gb G.Skill 3200 / Gigabyte Aorus RTX2080Ti Xterme / 2x Gigabyte Aorus NVMe M.2 1Tb / Corsair AX1200i / full liquid EK - Bitspower / circa 160 trattative nel mercatino |
|
|
|
|
|
#5 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
capito.
grazie 1000 |
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: Jun 2005
Città: Mestre (VE)
Messaggi: 1415
|
Se hai domande sul codice chiedi pure ... o se hai altri dubbi ...
__________________
IN WIN 909 / AMD Ryzen 9 3950X / Gigabyte X570 Aorus Xtreme / 4x8gb G.Skill 3200 / Gigabyte Aorus RTX2080Ti Xterme / 2x Gigabyte Aorus NVMe M.2 1Tb / Corsair AX1200i / full liquid EK - Bitspower / circa 160 trattative nel mercatino |
|
|
|
|
|
#7 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
Scusami mynos...
...poiche coloro che mi stanno insegnando a programmare (sto seguendo un corso) mi hanno imposto di non usare un foglio unico sapresti dirmi come potrei fare a risolvere questo errore??? Vedi ho fatto altri due\tre "programmini",sempre in visual studio 8(2005), quando eseguo il debug non trova errori fa per lanciarmi la pagina del browser ma poi mi da a tutti lo stesso identico "errore". il consiglio che mi da Visual Studio è "Usa la parola chiave "new" per creare una istanza di oggetto" Sinceramente non so cosa sia...e non so cosa fare....perdona la mia ignoranza e se puoi ti prego aiutami.
|
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Jun 2005
Città: Mestre (VE)
Messaggi: 1415
|
Scusa mi sono accorto solo ora che avevi scritto.
Questa è la pagina aspx modificata: Codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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>
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="CheckBox1" runat="server" Text="C"/><br />
<asp:CheckBox ID="CheckBox2" runat="server" Text="C++"/><br />
<asp:CheckBox ID="CheckBox3" runat="server" Text="C#"/><br />
<asp:CheckBox ID="CheckBox4" runat="server" Text="Visual Basic 6.0"/>
<br />
<asp:CheckBox ID="CheckBox5" runat="server" Text="VB.NET"/>
<br />
<asp:CheckBox ID="CheckBox6" runat="server" Text="Pascal"/><br />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Codice:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "hai scelto:<br/><b>"
Dim ctl As New Control
For Each ctl In Page.Controls(1).Controls
If TypeOf ctl Is CheckBox Then
If CType(ctl, CheckBox).Checked Then
Label1.Text += CType(ctl, CheckBox).Text & "<br/>"
End If
End If
Next
Label1.Text += "</b>"
End Sub
End Class
Poi nella dichiarazione da codice di controlli, bisogna usare As New per creare un' istanza dell' oggetto ... un po come in Java (anche senza il po). Attento poi che tu nel tuo codice hai usato CheckBoxList mentre in html hai usato CheckBox ... sono controlli diversi concettualmente anche se graficamente sono uguali e fanno la stessa cosa.
__________________
IN WIN 909 / AMD Ryzen 9 3950X / Gigabyte X570 Aorus Xtreme / 4x8gb G.Skill 3200 / Gigabyte Aorus RTX2080Ti Xterme / 2x Gigabyte Aorus NVMe M.2 1Tb / Corsair AX1200i / full liquid EK - Bitspower / circa 160 trattative nel mercatino |
|
|
|
|
|
#9 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
|
|
|
|
|
|
#10 |
|
Senior Member
Iscritto dal: Jun 2005
Città: Mestre (VE)
Messaggi: 1415
|
Guardati bene il codice che ti ho dato, se hai dubbi chiedi pure ...
Non prendertela ... nessuno nasce sapientone, l' importante è diventarlo studiando
__________________
IN WIN 909 / AMD Ryzen 9 3950X / Gigabyte X570 Aorus Xtreme / 4x8gb G.Skill 3200 / Gigabyte Aorus RTX2080Ti Xterme / 2x Gigabyte Aorus NVMe M.2 1Tb / Corsair AX1200i / full liquid EK - Bitspower / circa 160 trattative nel mercatino |
|
|
|
|
|
#11 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
Raga sono tornato
Sto sempre programmavdo in ASP.Net...devo realizzare un sito allacciato a un DB. Il problema nasce sul comando Insert mi dice "Errore nell'inserire il recordErrore di sintassi nell'istruzione INSERT INTO. INSERT INTO Cliente (Nome, Cognome, Datanascita, Codicefiscale, Indirizzo, Dataiscrizione, Username, Password)VALUES ('ciao', 'c', 'c', 'c', 'c', 'c', 'c', 'c')" Le "c" le ho messe per sbrigarmi ma ho provato anche con nomi completi ma nulla...potete aiutarmi...vi allego il codice del mio insert Dim strInsert As String strInsert = " INSERT INTO Cliente (" strInsert &= "Nome, Cognome, Datanascita, Codicefiscale, Indirizzo, Dataiscrizione, Username, Password)" strInsert &= "VALUES ('" strInsert &= txtNome.Text & "', '" strInsert &= txtCognome.Text & "', '" strInsert &= txtData.Text & "', '" strInsert &= txtCF.Text & "', '" strInsert &= txtIndirizzo.Text & "', '" strInsert &= txtIscrizione.Text & "', '" strInsert &= txtUsername.Text & "', '" strInsert &= txtPassword.Text & "')" Dim Insertcon As New OleDbConnection(Connection) Dim Insertcmd As New OleDbCommand(strInsert, Insertcon) Dim Insertreader As OleDbDataReader Dim Added As Integer Try Insertcon.Open() Added = Insertcmd.ExecuteNonQuery Catch err As Exception lblStatus.Text = "Errore nell'inserire il record" lblStatus.Text &= err.Message & strInsert Finally If (Not Insertcon Is Nothing) Then Insertcon.Close() End If End Try Dim SelectID As String SelectID = "SELECT * FROM Cliente" Dim conID As New OleDbConnection(Connection) Dim cmdID As New OleDbCommand(SelectID, conID) Dim readerID As OleDbDataReader conID.Open() readerID = cmdID.ExecuteReader() Do While readerID.Read() txtID.Text = readerID("IdCliente") Loop readerID.Close() If Added > 0 Then Dim URL As String = "libri.aspx?" URL &= "ID=" & txtID.Text Response.Redirect(URL) End If End Sub End Class Grazie |
|
|
|
|
|
#12 |
|
Senior Member
Iscritto dal: Jun 2005
Città: Mestre (VE)
Messaggi: 1415
|
Attento allo spazio iniziale prima di INSERT ... può essere quello l' errore.
Hai controllato bene poi i nomi delle colonne della tabella che corrispondano con quanto hai scritto? e che il loro tipo sia stringa? visto che hai usato tutte stringhe ...
__________________
IN WIN 909 / AMD Ryzen 9 3950X / Gigabyte X570 Aorus Xtreme / 4x8gb G.Skill 3200 / Gigabyte Aorus RTX2080Ti Xterme / 2x Gigabyte Aorus NVMe M.2 1Tb / Corsair AX1200i / full liquid EK - Bitspower / circa 160 trattative nel mercatino |
|
|
|
|
|
#13 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
ok ho fatto tutto quello che mi hai segnalato ma niente mynos.......
|
|
|
|
|
|
#14 |
|
Senior Member
Iscritto dal: Mar 2002
Città: Italy/Usa
Messaggi: 2817
|
a meno che vb.net non richieda espressamente i doppi apici nella insert (cosa che non credo) il tuo errore di sintassi è all'inizio:
Codice:
stringInsert = "INSERT INTO Cliente(campo1, campo2, etc.....) "
in sostanza NON dovresti fare:
stringInsert = "INSERT INTO Cliente("campo1, campo2, etc...") "
__________________
"Utilizzando atomi pentavalenti drogheremo il silicio di tipo n; Utilizzando atomi trivalenti drogheremo il silicio di tipo p; Utilizzando della cannabis ci drogheremo noi e vedremo il silicio fare cose impossibili" - DSDT-HowTo |
|
|
|
|
|
#15 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
Ok...Quindi dovrebbe essere sbagliata anche la sintassi del VALUES giusto??
grazie |
|
|
|
|
|
#16 | |
|
Senior Member
Iscritto dal: Mar 2002
Città: Italy/Usa
Messaggi: 2817
|
Quote:
ad esempio, tralasciando il linguaggio ed occupandoci solo della query, sarebbe semplicemente: Codice:
INSERT INTO Cliente(colonna1, colonna2, colonna3....) VALUES ('valore1', 'valore2', 'valore3' );
Codice:
stringInsert = "INSERT INTO Clienti(colonna1, colonna2, colonna3) VALUES('" & textBox1.Text & "', '" & textBox2.Text & "', '" & blablabla & "') "
Se posso permettermi di darti un consiglio, non usare questa tecnica in .net, ma inizia a cimentarti sull'uso dei "Parameters". Nel caso tuo specifico, su: OleDbCommand.Parameters.
__________________
"Utilizzando atomi pentavalenti drogheremo il silicio di tipo n; Utilizzando atomi trivalenti drogheremo il silicio di tipo p; Utilizzando della cannabis ci drogheremo noi e vedremo il silicio fare cose impossibili" - DSDT-HowTo |
|
|
|
|
|
|
#17 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
Problema risolto non avevo messo gli apici nel VALUES a,almeno non tutti,
Graize mille per l'aiuto tornerò presto con qualche altro problemino.... |
|
|
|
|
|
#18 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
Eccomi piu ignorante che mai....
...andando avanti con lo sviluppo del mio "sito" sono incappato in un altro errore dal quale non riesco a districarmi... In pratica prendo dei titoli di alcuni libri da un database li inserisco in una DropDownList e sino a qui tutto a posto......ora selezionato un libro una volta fatto click su ubn tasto inserisci tale titolo dovrebbe essere copiato in un "label" che funziona come una sorta di carrello.... Nell'istruzione "FillListaCarrello(dsLibreria, "Dettagli") (in cui libreria è il nome del mio Db e Dettagli quello di una tabella ) mi da il seguente errore : "Proprietà Select Command non dichiarata prima della chiamata a 'Fill' " Qualcuno puo aiutarmi per favore????
|
|
|
|
|
|
#19 |
|
Member
Iscritto dal: Jun 2006
Messaggi: 127
|
up
|
|
|
|
|
|
#20 |
|
Senior Member
Iscritto dal: Jan 2000
Città: Provincia di Parma
Messaggi: 724
|
Il data adapter che usi, non ha impostata la proprietà SelectCommand.
Dai un occhio qui: http://msdn2.microsoft.com/it-it/library/bh8kx08z.aspx Ciao
__________________
My Pc: Case Enermax Chakra - PSU Corsair HX520 - Gigabyte P35-DS3R - Core2 Duo E6550 - 6 Gb RAM Geil PC800 - 2x WD Caviar SE 320Gb (Raid1) - Xfx GeForce 8600Gt - Master Pioneer DVR111D - Samsung SM T220 - S.O. Windows 7 Ultimate x64 SP1 My blog: http://blogs.ugidotnet.org/alby |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 07:52.



















