Groups | Blog | Home
all groups > dotnet windows forms databinding > august 2004 >

dotnet windows forms databinding : refresh combobox bounded on dataset


b_nursel NO[at]SPAM yahoo.de
8/20/2004 7:19:56 AM
my combobox(cbo_Bezeichnung) is displaying data from
tbl_NCC_Gegenstaende. Now if i insert a new record in this table and i
want to refresh my combobox with this new added record is displaying
with the other records, too. How can i do it. It is very urgent.

My source code as follows:

SqlCeConnection myConnection = new
SqlCeConnection(myConnectionString);
string select="SELECT Bezeichnung_ID, Bezeichnung FROM
tbl_NCC_Gegenstaende ORDER BY Bezeichnung_ID";
SqlCeDataAdapter myDataAdapter = new SqlCeDataAdapter();
myDataAdapter.SelectCommand = new SqlCeCommand(select,myConnection);
SqlCeCommandBuilder myCommandBuilder = new
SqlCeCommandBuilder(myDataAdapter);

myConnection.Open();
DataSet ds=new DataSet();


myDataAdapter.Fill(ds,"tbl_NCC_Gegenstaende");


if(ds.Tables["tbl_NCC_Gegenstaende"].Rows.Count==0)
{
MessageBox.Show("Es sind noch keine Gegenstände eingetragen");
}
else
{
string[] NewRow = {"-1", "Neue Bezeichnung"};
ds.Tables["tbl_NCC_Gegenstaende"].Rows.Add (NewRow);

cbo_Bezeichnung.Items.Clear(); // cbo_Bezeichnung is my ComboBox
cbo_Bezeichnung.DataSource =ds.Tables["tbl_NCC_Gegenstaende"];
cbo_Bezeichnung.DisplayMember = "Bezeichnung";
cbo_Bezeichnung.ValueMember = "Bezeichnung_ID";
cbo_Bezeichnung.SelectedIndex = -1;


}
myConnection.Close();

SqlCeCommand cmd2= myConnection.CreateCommand();
myConnection.Open();
cmd2.CommandText = "INSERT INTO tbl_NCC_Gegenstaende (Bezeichnung_ID,
Bezeichnung) VALUES (5, 'Tisch')";
cmd2.ExecuteNonQuery();
myConnection.Close();

// Here i want to refresh my combobox with this inserted record is
also displaying in the combobox.

Fanor
8/20/2004 3:17:09 PM
It Looks u are updating the table directly , instead you should use
table.Addrow()

otherwise u need to clear the dataset and fill it again after each insert

[quoted text, click to view]

AddThis Social Bookmark Button