Showing posts with label back. Show all posts
Showing posts with label back. Show all posts

Monday, March 26, 2012

RowChanged

I'm trying to put a fix in on a web page I did awhile back. The email occasionally goes down on it. So I was going to write emails to a SQL Server Table, then every two minutes check for entries in the table, and send out the email if any exist, on success remove the record. I've done this. But running a thread for the life of the application and querrying every 2 minutes seems a little overkill. How can I, with C#/ASP.NET get an event for when a record is added to the database, so I can start the thread then, and also end it after it has successfully sent out all queued emails?

I've seen RowChanged, but not a lot of documentation on it's use, ie, does there have to be an open connection the whole time? Does there have to be a class overridden to catch the event?You should use a SQL Trigger.|||Actually, I'd probably create a SQL Server Agent Job that did that. You could schedule it to fire every couple of minutes. It's a service that's probably already running.

David

Wednesday, March 7, 2012

Row already belongs to another table.

I have a DataGrid that uses a DataTable as a DataSource. Call this table dt.
The DataGrid is editable so changes will be flushed back to the DataSource
(dt). I want to keep track of the changes so I created a duplicate table
(call it dtCopy). To see the changes I simply check every column in every ro
w
and find what has change. In theory this seems like it will work but I run
into a snag when adding a row. I get an exception from SQL indicating that
this row already belongs to another table. This I already know since I am
adding the row to both tables. Any ideas on how I can add a row to both
tables without this error/exception? Any better solution?
Thank you.On Thu, 15 Jun 2006 15:53:01 -0700, Kevin Burton
<KevinBurton@.discussions.microsoft.com> wrote:

>I get an exception from SQL indicating that
>this row already belongs to another table.
The only way I can imagine getting a message about a different table
than the INSERT target is if there is an INSERT TRIGGER on the target
table. You have not mentioned any such trigger.
Posting the exact message would probably be a good idea.
Roy Harvey
Beacon Falls, CT|||Actually, if it's the error that I'm thinking of, it's not a SQL error.
DataSets and Datatables are part of ADO.NET, not the data storage
layer.
Please post the error, but I think you'll be better off looking for
help in a newsgroup for ADO.NET.
Stu
Kevin Burton wrote:
> I have a DataGrid that uses a DataTable as a DataSource. Call this table d
t.
> The DataGrid is editable so changes will be flushed back to the DataSource
> (dt). I want to keep track of the changes so I created a duplicate table
> (call it dtCopy). To see the changes I simply check every column in every
row
> and find what has change. In theory this seems like it will work but I run
> into a snag when adding a row. I get an exception from SQL indicating that
> this row already belongs to another table. This I already know since I am
> adding the row to both tables. Any ideas on how I can add a row to both
> tables without this error/exception? Any better solution?
> Thank you.|||When you copy a row from one datatable to another, it is just referenced.
Thats why you are getting this error.
say you want to copy the rows from tbl1 to another datatable tbl2, then use
the itemarray method.. goes like this.. the exact syntax though you should b
e
checking :)
for(int i = 0;t < tbl1.Rows.Count;i++)
begin
tbl2.Rows.Add(tbl1.Rows(i).ItemArray)
end
-Omnibuzz (The SQL GC)
http://omnibuzz-sql.blogspot.com/