Home All Groups Group Topic Archive Search About

Column names and typed dataset

Author
21 Nov 2005 6:48 PM
AnHund
I came across one thing/problem regarding typed datasets in the case where
the column name has two words or has a dash in between the words in the
column name like:

        "E-mail" or "Expiry date"

In the select statment I use [E-mail] and [Expiry date] which works fine,
but the problem is that the

        OleDbCommandBuilder(adapter)

does not build correct update statements and I get an error ("Syntax error
in UPDATE statement") when trying to update a row with "E-mail" or "Expiry
date"

Other colums with a single word column name works just fine.

Any hints would be very much appreciated.

Thanks..

Please see code sample below (not complete with all details, just to get an
idea):


string SqlString = "SELECT CustomerID, Firstname, [E-mail], [Expiry date]
FROM Customers";

     // Create new dataset
     CustomerDataset customerDataset = new CustomerDataset();

     // Get customers
    db.Execute(customerDataset, "Customers");

    // Select row 1 (could be any other row)
    CustomerDataset.CustomerRow row = (CustomerDataset.CustomerRow)   

customerDataset.Customer.Rows[1];
    // Change some fields
    row.Firstname = "ZZ Top";
    row._E_mail = zz***@zz.com;

    // Then update data base with the changes
    connection.ConnectionString = ConnectionString;
    command.CommandText = SqlString;

   // Auto generate update statements
    OleDbCommandBuilder up = new OleDbCommandBuilder(adapter);

    // UPDATE FAILS WITH "Syntax error in UPDATE statement"
    adapter.Update(ds, tableName);   

NOTE: everything works just fine if the column names are one word like
"Email", "Expirydate" etc.

Author
22 Nov 2005 1:33 AM
Bart Mermuys
Hi,

Show quote
"AnHund" <AnH***@discussions.microsoft.com> wrote in message
news:02541C39-C3EC-4982-99FC-D3A6503CD563@microsoft.com...
>I came across one thing/problem regarding typed datasets in the case where
> the column name has two words or has a dash in between the words in the
> column name like:
>
>        "E-mail" or "Expiry date"
>
> In the select statment I use [E-mail] and [Expiry date] which works fine,
> but the problem is that the
>
>        OleDbCommandBuilder(adapter)
>
> does not build correct update statements and I get an error ("Syntax error
> in UPDATE statement") when trying to update a row with "E-mail" or "Expiry
> date"
>
> Other colums with a single word column name works just fine.
>
> Any hints would be very much appreciated.
>
> Thanks..
>
> Please see code sample below (not complete with all details, just to get
> an
> idea):
>
>
> string SqlString = "SELECT CustomerID, Firstname, [E-mail], [Expiry date]
> FROM Customers";
>
>     // Create new dataset
>     CustomerDataset customerDataset = new CustomerDataset();
>
>     // Get customers
>    db.Execute(customerDataset, "Customers");
>
>    // Select row 1 (could be any other row)
>    CustomerDataset.CustomerRow row = (CustomerDataset.CustomerRow)
>
> customerDataset.Customer.Rows[1];
>    // Change some fields
>    row.Firstname = "ZZ Top";
>    row._E_mail = zz***@zz.com;
>
>    // Then update data base with the changes
>    connection.ConnectionString = ConnectionString;
>    command.CommandText = SqlString;
>
>   // Auto generate update statements
>    OleDbCommandBuilder up = new OleDbCommandBuilder(adapter);

Try to set:
    up.QuotePrefix = "[";
    up.QuoteSuffix = "]";

before updating.

HTH,
Greetings


Show quote
>
>    // UPDATE FAILS WITH "Syntax error in UPDATE statement"
>    adapter.Update(ds, tableName);
>
> NOTE: everything works just fine if the column names are one word like
> "Email", "Expirydate" etc.
Author
22 Nov 2005 4:27 PM
AnHund
Thanks Bart,

Your solution to the problem just works perfectly.

Br. AnHund

Show quote
"Bart Mermuys" wrote:

> Hi,
>
> "AnHund" <AnH***@discussions.microsoft.com> wrote in message
> news:02541C39-C3EC-4982-99FC-D3A6503CD563@microsoft.com...
> >I came across one thing/problem regarding typed datasets in the case where
> > the column name has two words or has a dash in between the words in the
> > column name like:
> >
> >        "E-mail" or "Expiry date"
> >
> > In the select statment I use [E-mail] and [Expiry date] which works fine,
> > but the problem is that the
> >
> >        OleDbCommandBuilder(adapter)
> >
> > does not build correct update statements and I get an error ("Syntax error
> > in UPDATE statement") when trying to update a row with "E-mail" or "Expiry
> > date"
> >
> > Other colums with a single word column name works just fine.
> >
> > Any hints would be very much appreciated.
> >
> > Thanks..
> >
> > Please see code sample below (not complete with all details, just to get
> > an
> > idea):
> >
> >
> > string SqlString = "SELECT CustomerID, Firstname, [E-mail], [Expiry date]
> > FROM Customers";
> >
> >     // Create new dataset
> >     CustomerDataset customerDataset = new CustomerDataset();
> >
> >     // Get customers
> >    db.Execute(customerDataset, "Customers");
> >
> >    // Select row 1 (could be any other row)
> >    CustomerDataset.CustomerRow row = (CustomerDataset.CustomerRow)
> >
> > customerDataset.Customer.Rows[1];
> >    // Change some fields
> >    row.Firstname = "ZZ Top";
> >    row._E_mail = zz***@zz.com;
> >
> >    // Then update data base with the changes
> >    connection.ConnectionString = ConnectionString;
> >    command.CommandText = SqlString;
> >
> >   // Auto generate update statements
> >    OleDbCommandBuilder up = new OleDbCommandBuilder(adapter);
>
> Try to set:
>     up.QuotePrefix = "[";
>     up.QuoteSuffix = "]";
>
> before updating.
>
> HTH,
> Greetings
>
>
> >
> >    // UPDATE FAILS WITH "Syntax error in UPDATE statement"
> >    adapter.Update(ds, tableName);
> >
> > NOTE: everything works just fine if the column names are one word like
> > "Email", "Expirydate" etc.
>
>
>
Author
22 Nov 2005 5:11 AM
luxspes
AnHund wrote:
> I came across one thing/problem regarding typed datasets in the case where
> the column name has two words or has a dash in between the words in the
> column name like:

>         "E-mail" or "Expiry date"
>
> In the select statment I use [E-mail] and [Expiry date] which works fine,
> but the problem is that the
>
>         OleDbCommandBuilder(adapter)
>
> does not build correct update statements and I get an error ("Syntax error
> in UPDATE statement") when trying to update a row with "E-mail" or "Expiry
> date"
If you like the idea of having the SQL automatically generated for you
maybe you should take a look at http://www.nhibernate.org



Show quote

> Other colums with a single word column name works just fine.
>
> Any hints would be very much appreciated.
>
> Thanks..
>
> Please see code sample below (not complete with all details, just to get an
> idea):
>
>
> string SqlString = "SELECT CustomerID, Firstname, [E-mail], [Expiry date]
> FROM Customers";
>
>      // Create new dataset
>      CustomerDataset customerDataset = new CustomerDataset();
>
>      // Get customers
>     db.Execute(customerDataset, "Customers");
>
>     // Select row 1 (could be any other row)
>     CustomerDataset.CustomerRow row = (CustomerDataset.CustomerRow)   
>                                                                 
> customerDataset.Customer.Rows[1];
>     // Change some fields
>     row.Firstname = "ZZ Top";
>     row._E_mail = zz***@zz.com;
>
>     // Then update data base with the changes
>     connection.ConnectionString = ConnectionString;
>     command.CommandText = SqlString;
>   
>    // Auto generate update statements
>     OleDbCommandBuilder up = new OleDbCommandBuilder(adapter);
>
>     // UPDATE FAILS WITH "Syntax error in UPDATE statement"
>     adapter.Update(ds, tableName);   
>
> NOTE: everything works just fine if the column names are one word like
> "Email", "Expirydate" etc.

AddThis Social Bookmark Button