SqlDataAdapter

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I'm reading in a book and here there is something that I hope you may know.

Normally a DataAdapter can be defined like this
SqlDataAdapter custAdapter = new SqlDataAdapter("Select * from Customers",
thisConnection);
custAdapter.fill(thisDataSet,"Customers");

But the book is using a different syntax in one example like this
SqlDataAdapter detailAdapter = new SqlDataAdapter("Select * from [Order
Detail]", thisConnection);
detailAdapter.fill(thisDataSet,"Order Details");

So my question is about the brackets[] when specifying the
select clause in detailAdapter ?

//Tony
 
The table name "Order Details" has a space in it, so the brackets are used
to indicate it is a single name token.
 
Hello!

I'm reading in a book and here there is something that I hope you may know.

Normally a DataAdapter can be defined like this
SqlDataAdapter custAdapter = new SqlDataAdapter("Select * from Customers",
thisConnection);
custAdapter.fill(thisDataSet,"Customers");

But the book is using a different syntax in one example like this
SqlDataAdapter detailAdapter = new SqlDataAdapter("Select * from [Order
Detail]", thisConnection);
detailAdapter.fill(thisDataSet,"Order Details");

So my question is about the brackets[] when specifying the
select clause in detailAdapter ?

//Tony

As far as I am aware, square brackets are used to escape names in
sql.
So if you had a table named "select" you would have to write "select *
from [select]", because the sql-parser would interpret "select" as a
keyword otherwise.
In this case I assume there is a space between "Order" and "Detail",
in which case the brackets are also required to mark the beginning and
end of the name of the table.

hth,
Kevin Wienhold
 
Hello!

I'm reading in a book and here there is something that I hope you may know.

Normally a DataAdapter can be defined like this
SqlDataAdapter custAdapter = new SqlDataAdapter("Select * from Customers",
thisConnection);
custAdapter.fill(thisDataSet,"Customers");

But the book is using a different syntax in one example like this
SqlDataAdapter detailAdapter = new SqlDataAdapter("Select * from [Order
Detail]", thisConnection);
detailAdapter.fill(thisDataSet,"Order Details");

So my question is about the brackets[] when specifying the
select clause in detailAdapter ?

//Tony

Hi,

It's using the same syntax. In SQL you use [] to indicate that what is
in between them is an identifier, you use that a lot for example to
name columns in a select:

select productName [Product Name] ....
 
KWienhold said:
I'm reading in a book and here there is something that I hope you may know.

Normally a DataAdapter can be defined like this
SqlDataAdapter custAdapter = new SqlDataAdapter("Select * from Customers",
thisConnection);
custAdapter.fill(thisDataSet,"Customers");

But the book is using a different syntax in one example like this
SqlDataAdapter detailAdapter = new SqlDataAdapter("Select * from [Order
Detail]", thisConnection);
detailAdapter.fill(thisDataSet,"Order Details");

So my question is about the brackets[] when specifying the
select clause in detailAdapter ?

As far as I am aware, square brackets are used to escape names in
sql.

SQL in SQLServer dialect.

Other databases uses different conventions.

Arne
 
Arne said:
KWienhold said:
I'm reading in a book and here there is something that I hope you may
know.

Normally a DataAdapter can be defined like this
SqlDataAdapter custAdapter = new SqlDataAdapter("Select * from
Customers",
thisConnection);
custAdapter.fill(thisDataSet,"Customers");

But the book is using a different syntax in one example like this
SqlDataAdapter detailAdapter = new SqlDataAdapter("Select * from [Order
Detail]", thisConnection);
detailAdapter.fill(thisDataSet,"Order Details");

So my question is about the brackets[] when specifying the
select clause in detailAdapter ?

As far as I am aware, square brackets are used to escape names in
sql.

SQL in SQLServer dialect.

Other databases uses different conventions.

And I think it is much better to fix the names so that they
do not contain spaces than use [].

Arne
 
Back
Top