can't generate update command

G

Guest

I have the following statements that worked without a hitch on my laptop:
string sqlStr = "select * from table where id = @id";
SqlConnection conn = new SqlConnection(connStr);
SqlDataAdpapter sda = new SqlDataAdapter(sqlStr, conn);
sda.SelectCommand.Add(new SqlParameter("@id", SqlDbType.Int)).Value = val;
SqlCommandBuilder builder = new SqlCommandBuilder(sda);
DataTable dt = new DataTable();
sda.Fill(dt);
..... some update on dt ...
sda.Update(dt);

On a different machine, I got an error saying " Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information." The table already has primary key defined. There also doesn't seem to be a way to let the selectcommand return any key column information. Does anyone know what could be the cause of the problem? Many thanks!
 
M

Miha Markic [MVP C#]

Hi Bob,

Are you really sure that on target machine (do you have different database
servers?) your table has primary?
Is your table actually named table?
You might put in square brackets if it is so.
Anyway, I would advice you against using commandbuilder.
Rather, create adapters at design time - by drag&drop table from server
explorer perhaps.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

Bob D. said:
I have the following statements that worked without a hitch on my laptop:
string sqlStr = "select * from table where id = @id";
SqlConnection conn = new SqlConnection(connStr);
SqlDataAdpapter sda = new SqlDataAdapter(sqlStr, conn);
sda.SelectCommand.Add(new SqlParameter("@id", SqlDbType.Int)).Value = val;
SqlCommandBuilder builder = new SqlCommandBuilder(sda);
DataTable dt = new DataTable();
sda.Fill(dt);
... some update on dt ...
sda.Update(dt);

On a different machine, I got an error saying " Dynamic SQL generation for
the UpdateCommand is not supported against a SelectCommand that does not
return any key column information." The table already has primary key
defined. There also doesn't seem to be a way to let the selectcommand
return any key column information. Does anyone know what could be the cause
of the problem? Many thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top