Column Data Type problem (ADO.NET, C#)
- From: nvx2004@xxxxxxxxxxx
- Date: 31 Jul 2006 04:19:15 -0700
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
.
- Follow-Ups:
- Re: Column Data Type problem (ADO.NET, C#)
- From: Stephen Howe
- Re: Column Data Type problem (ADO.NET, C#)
- Prev by Date: RE: Insert with automatic Exists check?
- Next by Date: Re: Column Data Type problem (ADO.NET, C#)
- Previous by thread: Text file using ADO. DELETE failed
- Next by thread: Re: Column Data Type problem (ADO.NET, C#)
- Index(es):
Relevant Pages
|