Menu
Home
Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Database
Database General Discussion
Clearing a dataset?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="jlwilliams1" data-source="post: 5864" data-attributes="member: 2322"><p>I'm writing a windows service that periodically goes out to a SQL table and checks it for new records. I connect ok and fill the dataset ok, but how do I clear the dataset once I'm done with it? What's happening is that evertime the service goes to check the table, it fills the dataset, appending from the end. So if I start with 2 new records in the dataset, at the next check the dataset will have 4, then 6, etc. </p><p></p><p>I've tried using dataset.clear and dataset.Tables("tablename").Rows.Clear(), but neither seems to work. </p><p></p><p>Any clues or ideas?</p><p></p><p>Here's the code I'm using:</p><p></p><p>[CODE] </p><p>SelectStatement = "SELECT * FROM Test WHERE Newrecord = 'Y'" cmd.CommandText = SelectStatement</p><p></p><p>cmd.CommandType = CommandType.Text</p><p></p><p>cmd.Connection = connect</p><p></p><p>da.SelectCommand = cmd</p><p></p><p>connect.Open()</p><p></p><p>ds.Clear()</p><p></p><p>da.Fill(ds, "Test")</p><p></p><p>If ds.Tables(0).Rows.Count <= 0 Then</p><p></p><p>da.SelectCommand.Connection.Close()</p><p></p><p>Exit Sub</p><p></p><p>End If</p><p></p><p>connect.Close()</p><p></p><p>numrecs = ds.Tables(0).Rows.Count</p><p></p><p></p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="jlwilliams1, post: 5864, member: 2322"] I'm writing a windows service that periodically goes out to a SQL table and checks it for new records. I connect ok and fill the dataset ok, but how do I clear the dataset once I'm done with it? What's happening is that evertime the service goes to check the table, it fills the dataset, appending from the end. So if I start with 2 new records in the dataset, at the next check the dataset will have 4, then 6, etc. I've tried using dataset.clear and dataset.Tables("tablename").Rows.Clear(), but neither seems to work. Any clues or ideas? Here's the code I'm using: [CODE] SelectStatement = "SELECT * FROM Test WHERE Newrecord = 'Y'" cmd.CommandText = SelectStatement cmd.CommandType = CommandType.Text cmd.Connection = connect da.SelectCommand = cmd connect.Open() ds.Clear() da.Fill(ds, "Test") If ds.Tables(0).Rows.Count <= 0 Then da.SelectCommand.Connection.Close() Exit Sub End If connect.Close() numrecs = ds.Tables(0).Rows.Count [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
Home
Forums
Database
Database General Discussion
Clearing a dataset?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom