Column Data Type problem (ADO.NET, C#)



Hi,
I need to be able to add or remove columns from an Access database
table (table is bound to a DataGridView). I know I have to use ALTER
TABLE to do this. After I add a System.String column (AllowDBNull =
false, MaxLength = 35) to my DataSet and a VARCHAR(35) column to the DB
("ALTER TABLE tbl ADD col VARCHAR(35) NOT NULL" ->
cmd.ExecuteNonQuery()) I'm able to generate correct INSERT, DELETE and
UPDATE commands using CommandBuilder, but dAdapter.Update(dSet, "tbl")
ends up in an exception "Data types in the expression do not match." In
case I do not add any columns .Update(...) is executed without an
exception being thrown.

Here's the code:

dSet.Tables["tbl"].Columns.Add("col");
dSet.Tables["tbl"].Columns["col"].MaxLength = 35;

// column is filled in with values which I need to be there (in case
// this would be done after AllowDBNull = false an exception
// would be thrown...)

dSet.Tables["tbl"].Columns["col"].AllowDBNull = false;

// a column is added to the DataGridView and bound to the dSet column
// created above now

// other code here

OleDbCommand cmd = new OleDbCommand("ALTER TABLE tbl ADD col
VARCHAR(35) NOT NULL", conn);
conn.Open();
cmd.ExecuteNonQuery(); // columns in dSet match columns in DB now
bindingSource.EndEdit();
dAdapter.Update(dSet, "tbl");
conn.Close();

I'm not able to figure out why this doesn't work... Any help would be
appreciated.

With regards
nvx

.



Relevant Pages

  • Column Data Type problem (ADO.NET, C#)
    ... table (table is bound to a DataGridView). ... UPDATE commands using CommandBuilder, but dAdapter.Update ... ends up in an exception "Data types in the expression do not match." ... // columns in dSet match columns in DB now ...
    (microsoft.public.data.oledb)
  • Column Data Type problem (ADO.NET, C#)
    ... table (table is bound to a DataGridView). ... UPDATE commands using CommandBuilder, but dAdapter.Update ... ends up in an exception "Data types in the expression do not match." ... // columns in dSet match columns in DB now ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Column Data Type problem (ADO.NET, C#)
    ... I can't afford to use AutoGenerateColumns. ... table (table is bound to a DataGridView). ... ends up in an exception "Data types in the expression do not match." ... // columns in dSet match columns in DB now ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Column Data Type problem (ADO.NET, C#)
    ... table (table is bound to a DataGridView). ... UPDATE commands using CommandBuilder, but dAdapter.Update ... ends up in an exception "Data types in the expression do not match." ... // columns in dSet match columns in DB now ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: BindingNavigator AddNew - Fehlermeldung
    ... Mal im DataGridView, mal im Dataset, ... Und wenn man kein DataGridView benutzt, ... Die Controls haben Validating Events, ... aber dort kann man schwer eine Constraint Exception vorhersehen. ...
    (microsoft.public.de.german.entwickler.dotnet.datenbank)