M
Marina
Hi,
Running into an odd issue here. Only happens on a SQL Server 2005 database.
Consider this code:
Dim command As New SqlDataAdapter("Select Col1,Col2 FROM MyTable
WHERE Col1='abc'", conn)
Dim dt As New DataTable
Dim builder As New SqlCommandBuilder(command)
command.Fill(dt)
dt.Rows(0)("Col2") = "ADMIN"
command.Update(dt)
In this case Col1 is the primary key for MyTable.
If the database in question is on a SQL Server 200 machine, everything works
great.
If the database in question is on a SQL Server 2005 machine, there is a
'Dynamic SQL generation is not supported against a SelectCommand that does
not return any base table information.'
Now, not only is Col1 defined as the primary key, it is also being selected
here!
Here is the odd part, if I change the code to the following, everything
works great even on 2005:
Dim command As New SqlDataAdapter("Select Col1,Col2 FROM MyTable
WHERE Col1='abc'", conn)
Dim dt As New DataTable
Dim builder As New SqlCommandBuilder(command)
command.Fill(dt)
dt.Rows(0)("Col2") = "ADMIN"
command.SelectCommand.CommandText="Select Col1,Col2 FROM MyTable"
command.Update(dt)
Notice, that all I have done, is changed the SELECT statement right before
the update takes place, to not include the WHERE clause.
Now, everything is updated correctly.
I would like to reiterate, how everything works perfectly the way it
originally was as long as the database is on SQL Server 2000.
What gives?
Is this a known issue?
Running into an odd issue here. Only happens on a SQL Server 2005 database.
Consider this code:
Dim command As New SqlDataAdapter("Select Col1,Col2 FROM MyTable
WHERE Col1='abc'", conn)
Dim dt As New DataTable
Dim builder As New SqlCommandBuilder(command)
command.Fill(dt)
dt.Rows(0)("Col2") = "ADMIN"
command.Update(dt)
In this case Col1 is the primary key for MyTable.
If the database in question is on a SQL Server 200 machine, everything works
great.
If the database in question is on a SQL Server 2005 machine, there is a
'Dynamic SQL generation is not supported against a SelectCommand that does
not return any base table information.'
Now, not only is Col1 defined as the primary key, it is also being selected
here!
Here is the odd part, if I change the code to the following, everything
works great even on 2005:
Dim command As New SqlDataAdapter("Select Col1,Col2 FROM MyTable
WHERE Col1='abc'", conn)
Dim dt As New DataTable
Dim builder As New SqlCommandBuilder(command)
command.Fill(dt)
dt.Rows(0)("Col2") = "ADMIN"
command.SelectCommand.CommandText="Select Col1,Col2 FROM MyTable"
command.Update(dt)
Notice, that all I have done, is changed the SELECT statement right before
the update takes place, to not include the WHERE clause.
Now, everything is updated correctly.
I would like to reiterate, how everything works perfectly the way it
originally was as long as the database is on SQL Server 2000.
What gives?
Is this a known issue?