Asp. Net C#... posto il codice
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
OdbcConnection Conn = new OdbcConnection("Dsn=MS Access Database;dbq=percorso \\Supermarket.mdb;defaultdir=Cercorso;driverid=25;fil=MS Access;maxbuffersize=2048;pagetimeout=5;uid=admin" );
Conn.Open();
OdbcCommand command = new OdbcCommand("SELECT DescProdotto from Prodotti", Conn);
OdbcDataReader odr = command.ExecuteReader();
DropDownList1.Items.Clear();
ListBoxElementiSpesa.Items.Clear();
while (odr.Read())
{
DropDownList1.Items.Add(odr.GetString(0));
ListBoxElementiSpesa.Items.Add(odr.GetString(0));
}
odr.Close();
Conn.Close();
}
protected void ButtonInsert_Click(object sender, EventArgs e)
{
OdbcConnection Conn2 = new OdbcConnection("Dsn=MS Access Database;dbq=Cercorso\\Supermarket.mdb;defaultdir=C
ercorso;driverid=25;fil=MS Access;maxbuffersize=2048;pagetimeout=5;uid=admin" );
Conn2.Open();
OdbcCommand command2 = new OdbcCommand("INSERT INTO [Prodotti] (DescProdotto,Unità,PrezzoUnità) VALUES "
+ "('" + TextBoxNewProd.Text + "'," + Convert.ToInt32(TextBoxMeasure.Text) + " , " + Convert.ToInt32(TextBoxPrice.Text) + ")", Conn2);
command2.ExecuteNonQuery();
Conn2.Close();
TextBoxMeasure.Text = string.Empty; // queste sono le textbox in cui inserisco
TextBoxNewProd.Text = string.Empty;
TextBoxPrice.Text = string.Empty;
}
protected void ButtonInserisci_Click(object sender, EventArgs e)
{
ListBoxElementiScelti.Items.Add(ListBoxElementiSpe sa.SelectedItem);
}
}
ListboxElementiSpesa viene aggiornata con un comando al page Load. Quindi potrebbe essere che non trova piu la selected item....corretto?

ercorso;driverid=25;fil=MS Access;maxbuffersize=2048;pagetimeout=5;uid=admin" );
Rispondi quotando