Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 DataSets - Why is no error called

Author  Topic 

SQLError
Yak Posting Veteran

63 Posts

Posted - 2005-01-18 : 22:13:33
I have the following code I am trying in C#.net

'--------------------

SqlConnection con = new SqlConnection("etc....")

SqlDataAdapter adapter;
DataSet ds;

ds = new DataSet();

string query = "SELECT * FROM TEST";
adapter = new SqlDataAdapter(query,con);



adapter.Fill(ds, "TEST");


string insertQuery = "THIS IS CRAP";
adapter.InsertCommand = new SqlCommand(insertQuery, con);

adapter.Update(ds,"TEST");

'-----------------------------

Why isnt an error produced when insertQuery is not a valid
SQL command?

chadmat
The Chadinator

1974 Posts

Posted - 2005-01-19 : 12:09:53
I'm sure if you try to insert records it will give you an error.

-Chad

http://www.clrsoft.com

Software built for the Common Language Runtime.
Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2005-01-19 : 12:29:15
I think you need to add records to the data tables stored inside of the data set before you call your update method of the data adapter object.

Dustin Michaels
Go to Top of Page

SQLError
Yak Posting Veteran

63 Posts

Posted - 2005-01-20 : 18:21:52
adapter.InsertCommand = new SqlCommand(insertQuery, con);

Isnt this the insert
Go to Top of Page

chadmat
The Chadinator

1974 Posts

Posted - 2005-01-21 : 11:45:24
No. That is just setting the insert command of the DataAdapter to your bogus statement. Add some rows to the table, then try and update the database. It will fail.

-Chad

http://www.clrsoft.com

Software built for the Common Language Runtime.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-21 : 11:47:01
you call the update/insert/delete with:
DataSet ds = new DataSet();
...
ds.Update()

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -