Forum » Programiranje » Osveževanje podatkov v comboboxu
Osveževanje podatkov v comboboxu
brinovcek ::
Zanima me, kako bi dodal/osežil seznam podatkov v combobox po tem ko sem že naložil podatke v dataset, iz katerega se podatke črpa za prikaz in v bazo dodal še nekaj novih podatkov. Ni mi jasno zakaj se ne naložijo ob vsakem odiranju forma ponovno podatki iz baze v dataset in me zanima kaj bi moral v kodi spremeniti da bi se stvar osveževala oz posodabljala ob vsakem odpiranju? v Formu imam tudi en gumb ki bi mi stvari ponovno naložil vendar mi ob pristisku na gumb javi napake:
************** Exception Text **************
System.ArgumentException: This causes two bindings in the collection to bind to the same property.
Parameter name: binding
at System.Windows.Forms.ControlBindingsCollection.CheckDuplicates(Binding binding)
at System.Windows.Forms.Binding.CheckBinding()
at System.Windows.Forms.Binding.SetBindableComponent(IBindableComponent value)
at System.Windows.Forms.ControlBindingsCollection.AddCore(Binding dataBinding)
__________________________________________________________________________________________________________________________
Program:
public partial class Projekt : Form
{
string DN, Ime, Opis;
int ID;
//static int i = 0; //index for strArraylist
DateTime Datum;
public Projekt()
{
InitializeComponent();
napolniProjekt();
napolniDelavca();
}
private void Projekt_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'bazaDataSet1.Storitve' table. You can move, or remove it, as needed.
this.storitveTableAdapter.Fill(this.bazaDataSet1.Storitve);
}
public void napolniProjekt()
{
DataViewManager dview = new DataViewManager();
OleDbConnection myConn = null;
OleDbDataAdapter Adapter=null;
DataSet dset=null;
DataBindings.Clear();
try
{
//open the connection to the database
myConn = new OleDbConnection();
myConn.ConnectionString = connection();
myConn.Open();
}
catch (OleDbException ex)
{
MessageBox.Show("Error in connection ..." + ex.Message);
}
string sqlStr = "SELECT ID_Projekta,Delovni_nalog,Ime,Opis,Dat_Zacetka FROM Projekt WHERE Zaprt=false";
//Instantiate a DataAdapter by passing the sqlStr and Connection.
//now data is in raw form
Adapter = new OleDbDataAdapter(sqlStr, myConn);
//Instantiate a DataSet
dset = new DataSet();
dset.Clear();
//Gets a collection that provides the master mapping
// between a source table and a DataTable
Adapter.TableMappings.Add("Table", "Projekt");
Adapter.Fill(dset);
dview = dset.DefaultViewManager;
comboBox1.DataSource = dview;
comboBox3.DataSource = dview;
this.comboBox1.DisplayMember = "Projekt.Ime";
this.comboBox3.DisplayMember = "Projekt.Delovni_nalog";
//DataBinding for the TextBox controls
this.datum.DataBindings.Add("Text", dview, "Projekt.Dat_Zacetka");
this.textBox3.DataBindings.Add("Text", dview, "Projekt.Opis");
this.textBox4.DataBindings.Add("Text", dview, "Projekt.ID_Projekta");
// Close the connection to the database.
myConn.Close();
}
private void button3_Click(object sender, EventArgs e)
{
DataBindings.Clear();
napolniProjekt();
}
Prosim za pomoč, če kdo ve, kaj je treba spremenit ali padodatk da stvar dela tako kot želim.
Hvala
************** Exception Text **************
System.ArgumentException: This causes two bindings in the collection to bind to the same property.
Parameter name: binding
at System.Windows.Forms.ControlBindingsCollection.CheckDuplicates(Binding binding)
at System.Windows.Forms.Binding.CheckBinding()
at System.Windows.Forms.Binding.SetBindableComponent(IBindableComponent value)
at System.Windows.Forms.ControlBindingsCollection.AddCore(Binding dataBinding)
__________________________________________________________________________________________________________________________
Program:
public partial class Projekt : Form
{
string DN, Ime, Opis;
int ID;
//static int i = 0; //index for strArraylist
DateTime Datum;
public Projekt()
{
InitializeComponent();
napolniProjekt();
napolniDelavca();
}
private void Projekt_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'bazaDataSet1.Storitve' table. You can move, or remove it, as needed.
this.storitveTableAdapter.Fill(this.bazaDataSet1.Storitve);
}
public void napolniProjekt()
{
DataViewManager dview = new DataViewManager();
OleDbConnection myConn = null;
OleDbDataAdapter Adapter=null;
DataSet dset=null;
DataBindings.Clear();
try
{
//open the connection to the database
myConn = new OleDbConnection();
myConn.ConnectionString = connection();
myConn.Open();
}
catch (OleDbException ex)
{
MessageBox.Show("Error in connection ..." + ex.Message);
}
string sqlStr = "SELECT ID_Projekta,Delovni_nalog,Ime,Opis,Dat_Zacetka FROM Projekt WHERE Zaprt=false";
//Instantiate a DataAdapter by passing the sqlStr and Connection.
//now data is in raw form
Adapter = new OleDbDataAdapter(sqlStr, myConn);
//Instantiate a DataSet
dset = new DataSet();
dset.Clear();
//Gets a collection that provides the master mapping
// between a source table and a DataTable
Adapter.TableMappings.Add("Table", "Projekt");
Adapter.Fill(dset);
dview = dset.DefaultViewManager;
comboBox1.DataSource = dview;
comboBox3.DataSource = dview;
this.comboBox1.DisplayMember = "Projekt.Ime";
this.comboBox3.DisplayMember = "Projekt.Delovni_nalog";
//DataBinding for the TextBox controls
this.datum.DataBindings.Add("Text", dview, "Projekt.Dat_Zacetka");
this.textBox3.DataBindings.Add("Text", dview, "Projekt.Opis");
this.textBox4.DataBindings.Add("Text", dview, "Projekt.ID_Projekta");
// Close the connection to the database.
myConn.Close();
}
private void button3_Click(object sender, EventArgs e)
{
DataBindings.Clear();
napolniProjekt();
}
Prosim za pomoč, če kdo ve, kaj je treba spremenit ali padodatk da stvar dela tako kot želim.
Hvala
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | C# težavaOddelek: Programiranje | 3703 (2549) | mladec |
» | [C#,SQL]Oddelek: Programiranje | 1238 (1151) | JanOlMajti |
» | Baza & c#Oddelek: Programiranje | 4153 (3211) | xardas |
» | [C#] ne dodaja podatkov v bazoOddelek: Programiranje | 1579 (1428) | alesp56 |
» | razložitev nekaterij elementov v visual studio 05Oddelek: Programiranje | 2105 (1910) | darkolord |