|
How many rows affected does ExecuteNonQuery() return? Do you use a SqlTransaction[^] to Commit the changes to the database?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
It is affecting one row each time the query is executed
|
|
|
|
|
So do you commit the insert using the SqlTransaction.Commit method?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
no, how should I do that? I haven't used that method at all for now, can you pls give me some help how should i use it? Thx
|
|
|
|
|
|
thx, I will check it out now...
|
|
|
|
|
I use it the informations what you provide me, and it gives me error after the ExecuteNonQuery line, here is how I tried to solve:
SqlTransaction transaction;
transaction = conn.BeginTransaction("BeginTransaction");
SqlCommand command = conn.CreateCommand();
try
{
command.CommandText = query;
command.ExecuteNonQuery();
transaction.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.ToString(), ex);
}
finally
{
conn.Close();
}
This is the exception:
System.InvalidOperationException: ExecuteNonQuery requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized.
|
|
|
|
|
You forgot to insert command.Transaction = transaction before executing the query.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
So do you get an error?
Are you attaching the correct database file when you look for the data?
|
|
|
|
|
I do not get any error, I am going through each line of the code, everything seems OK, the right DB is attached and at the end I do not get anything in the DB, is the ExecuteNonQuery method declared ok?
|
|
|
|
|
By the way, your code is also vulnerable to SQL injections[^], you should fix that
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You are facing a common problem here I suspect, where the database is being copied over with a default instance. Basically, what is happening is that you have a default version of the database which is being copied over every time you run the application.
|
|
|
|
|
Any help with that, how I can solve?? Thx
|
|
|
|
|
The article does describe how to solve it. Look in the section "Parameterised Queries" in the article
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I have 2 windows forms, lets say Form1 and Form2........after designing I came to knowe that Form2 should execute before Form1...........how can I do that........
|
|
|
|
|
Depends on how the first form is created and displayed. Usually, if you create a simple Windows Forms application, then in your source file Program.cs you will find something like this:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
There you can simply change new Form1() to new Form2() (or their correct form type name).
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
Hey just change in Program.Cs
<br />
[STAThread]<br />
static void Main()<br />
{<br />
Application.EnableVisualStyles();<br />
Application.SetCompatibleTextRenderingDefault(false);<br />
Application.Run(new Form2());
}<br />
|
|
|
|
|
Hi,
I am using filesystemwatcher to mononitor a folder when changes occur to files in that folder.
I am happy with the changes it detects and it seems it is working correctly.
Question:
How is it possible to display the notifyfilter which gets detected i.e. size or filename, LastWrite, etc...
Thanks
|
|
|
|
|
|
Hi,
Thanks for the link.
Un-fortunately I do not see anything relatinig to my issue.
I am basically tring to detect what has exactly changed.
For example, I detect e.ChangeType where e is FileSystemEventArgs
But do not detect whether it is a size or creationtime or lastaccess or what change it exactly is.
Thanks
|
|
|
|
|
i think if you check The tool and code throughly you will get your answer.
|
|
|
|
|
Are you able to point me to it please?
Because I do not find that bit
Thanks
|
|
|
|
|
Hi,
I have checked the code again.
There does not seem to be what i am after.
I basically would like to detect the kind of the ChangeType whether it is size change or anything else that has caused the notifyfilter.
Thanks
|
|
|
|
|
Looking at the FileSystemEventArgs[^] members it doesn't seem like there's a way to find out this information.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|