I have the following code:
private void FillData() {
try {
// this is the adapter
dataAdapter = new SqlDataAdapter("Select username, isnull(password,'') from Credentials", connectionString);
SqlCommandBuilder cmb = new SqlCommandBuilder(dataAdapter);
// populate new data and bind it.
DataTable table = new DataTable();
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
catch (Exception e) {
MessageBox.Show("Error " +e);
}
}
private void ManualGeneratedDGF_Load(object sender, EventArgs e) {
dataGridView1.DataSource = bindingSource1;
}
private void button1_Click(object sender, EventArgs e) {
bindingSource1 = (BindingSource) dataGridView1.DataSource;
DataTable ds = new DataTable();
ds = (DataTable) bindingSource1.DataSource;
dataAdapter.Update(ds);
}
I don't understand why the above doesn't populate the code properly when I click the Save Button. I have a username and password int eh datagrid but when I click the Save button, it inserts the username properly but not the password?