|
And how do you tkink am I suppose to find the cause of the problem with break points if the break point pointing to the value of checkboxes, shows me the wrong value when I use the button from the toolbar and the correct value when I use the button from the datagrid? Does this takes me to any conclusion? It just confirms that it is not filling the checkboxes correctly, not why this should be happening.
|
|
|
|
|
Member 11449447 wrote: It just confirms that it is not filling the checkboxes correctly, not why this should be happening. Actually, it confirms that there is a bug in your code, and the debugger will help you to identify where that bug is.
|
|
|
|
|
So now you know the value being returned is not correct. Now you have to use the debugger to find out why. It's a tool that allows you to inspect variable contents as the code is running, so USE IT! Does the code that populates the controls work correctly? You better go verify that.
Also, the debugger is a tool that is used to correct YOU. Your understanding of what the code is doing is usually wrong. The debugger helps you understand your code AND DATA better. In development work, chances are high that your code is written to handle perfect data but it falls on its face when it encounters something that isn't perfect. The debugger helps you find these cases and adjust your code.
|
|
|
|
|
Member 11449447 wrote: string Cmd = "Select * from lojas where NIF ='" + grid_lic.CurrentRow.Cells[1].Value + "' and loja ='" + grid_lic.CurrentRow.Cells[2].Value + "'";
OdbcCommand cm2 = new OdbcCommand(Cmd, con);
OdbcDataReader dr = cm2.ExecuteReader();
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
Also, you should always wrap objects which implement IDisposable in a using block, to ensure that their resources are released properly.
using (OdbcConnection con = new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=xxx; database=licenciamento; uid=estagio; password=1234; option = 3 "))
{
con.Open();
using (OdbcCommand cm2 = new OdbcCommand("Select * from lojas where NIF = ? and loja = ?", con))
{
cm2.Parameters.AddWithValue("NIF", grid_lic.CurrentRow.Cells[1].Value);
cm2.Parameters.AddWithValue("loja", grid_lic.CurrentRow.Cells[2].Value);
using (OdbcDataReader dr = cm2.ExecuteReader())
{
}
}
using (OdbcCommand cm = new OdbcCommand("insert into licenciamentoloja (bloqueador, EArtigo) values (?, ?)", con))
{
cm.Parameters.AddWithValue("@bloqueador", bloqueador);
cm.Parameters.AddWithValue("@EArtigo", EArtigo);
cm.ExecuteNonQuery();
}
}
Member 11449447 wrote: if (grid_lic.CurrentRow.Cells[3].Value.ToString() != "" | grid_lic.CurrentRow.Cells[3].Value.ToString() == "True")
You're using the non-short-circuiting boolean operator | . In the vast majority of cases (including this one), that's the wrong operator to use. You should use the short-circuiting operator || instead.
if (grid_lic.CurrentRow.Cells[3].Value.ToString() != "" || grid_lic.CurrentRow.Cells[3].Value.ToString() == "True")
However, that still doesn't make any sense. If the value of the cell is not an empty string, then the first condition is true. If it is an empty string, then there's no way it can be equal to "True", so the second condition is false. The whole statement is equivalent to:
if (grid_lic.CurrentRow.Cells[3].Value.ToString() != "")
Member 11449447 wrote: public void BD_Conexao()
As Griff said, this method does nothing useful. It looks like you're trying to initialize and open a connection object stored in a class-level field called con , but you've declared a local variable of the same name instead.
Storing connection objects in fields is generally a bad idea. You should created and open the connection within the method that uses it, wrapped in a using block. Have a single method to create and open a new connection object, and return that connection:
public OdbcConnection BD_Conexao()
{
var result = new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=xxx; database=licenciamento; uid=estagio; password=1234; option = 3 ");
result.Open();
return result;
}
Then call that method from your other methods when you need to connect to the database:
using (OdbcConnection con = BD_Conexao())
{
...
}
Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]
SQL injection attack mechanics | Pluralsight [^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I´ve made all the changes according to your advices and it remains with the same error. But I solved this issue by using preformclick event in the button not working to triger the button click event that works, and setting this invisible in the datagrid (not by the invisible property but rather by managing the colors in the design).
Regarding your observation concerning the expression:
if (grid_lic.CurrentRow.Cells[3].Value.ToString() != "" || grid_lic.CurrentRow.Cells[3].Value.ToString() == "True")
bloqueador = 1;
else
bloqueador = 0;
it should be an '&' instead of a '||', the same is to say:
if(grid_lic.CurrentRow.Cells[3].Value.ToString() == "True")
bloqueador = 1;
else
bloqueador = 0;
which is equivalent to:
if(grid_lic.CurrentRow.Cells[3].Value.ToString() == "False" ||grid_lic.CurrentRow.Cells[3].Value.ToString() == "" )
bloqueador = 0;
else
bloqueador = 1;
since cell[3] or is empty or has the value 'true' or 'false'.
|
|
|
|
|
how to parse xml recusive based on directory and search criteria to get file name
<FileSystem>
<Drives>
<Drive name="C:">
<Folder name="data">
<Folder name="CSLogs">
<Folder name="Applications">
<Folder name="Citrix">
<Folder name="XenDesktop Installer">
<Folder name="MSI Log Files">
<File Name="BrokerAgent_x64311392187.txt" />
<File Name="CitrixCse_x641365171634.txt" />
<File Name="DirectorVDAplugin_x64276896625.txt" />
<File Name="IcaWS_x64397216209.txt" />
<File Name="MachineIdentityServiceAgent_x64492650649.txt" />
<File Name="MachineManagementProvider_x64407826716.txt" />
<File Name="personalvDisk_x64359317401.txt" />
<File Name="profilemgt_x641717284940.txt" />
<File Name="PzAppV_VDA_x641126819295.txt" />
<File Name="UpsClient_x641677360187.txt" />
<File Name="VdaMonitorPlugin_x64958367608.txt" />
<File Name="WMIProxy_x64801526517.txt" />
</Folder>
<File Name="XenDesktop Installation.log" />
</Folder>
<File Name="23157CIXXenDesktopVirtFx_Popup.log" />
<File Name="FixPolicyCorruption.ps1.log" />
</Folder>
modified 7-Jan-16 23:08pm.
|
|
|
|
|
Please do not repost your question. You need will need to show code you have tried and where you are stuck. Also, why this muh of blank space? This is what may do:
- Remove the other post with same question.
- Update this post with formatted relevant code
- Tell us where exactly are you stuck.
"You'd have to be a floating database guru clad in a white toga and ghandi level of sereneness to fix this goddamn clusterfuck.", BruceN[ ^]
|
|
|
|
|
|
To "get the FileName" by ... what ? Do you need to essentially de-serialize the entire XML stream into a usable object/Class structure ... that you could use do complex queries on ?
Or, is your need more simple, for example: given a Directory string filepath return all the Files in that Directory as a string[] ?
«Tell me and I forget. Teach me and I remember. Involve me and I learn.» Benjamin Franklin
|
|
|
|
|
|
Since that is an article, you might get a better response talking direct to the author.
There is a message area at the bottom for that purpose.
But it is quite old, so you might be even better off looking for a version that isn't ten years old anyway...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi.
if i have
class Program
{
static void Main(string[] args)
{
Task task1 = Task.Factory.StartNew(() => doStuff());
Task task2 = Task.Factory.StartNew(() => doStuff());
Task task3 = Task.Factory.StartNew(() => doStuff());
Task.WaitAll(task1, task2, task3);
Console.WriteLine("All threads complete");
}
static void doStuff()
{
//do stuff here
}
}
how i stop only one, anyone?
how i stop task2 only, for example?
|
|
|
|
|
This not help ? Task Cancellation[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
The standard way to do this is to use a CancellationToken from a CancellationTokenSource for each one that you want to cancel. You assign this token when you create your task. Your code would look something like this:
private IDictionary<string, CancellationTokenSource> taskToCancellationToken = new Dictionary<string, CancellationTokenSource>();
private Task DoSomething(string taskName, Action operation)
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
taskToCancellationToken.Add(taskName, tokenSource);
return Task.Factory.StartNew(operation, tokenSource.Token);
} Then, you can simply do something like this
public void QueueTasks()
{
Task.WaitAll(DoSomething("Task1", doStuff), DoSomething("Task2", doStuff), DoSomething("Task3", doStuff));
}
private void doStuff()
{
taskToCancellationToken["Task2"].Cancel();
}
This space for rent
|
|
|
|
|
if the "some signal" exists only on the QueueTasks func, how i Cancel the task? i can call taskToCancellationToken["Task2"].Cancel() from there and will work?
|
|
|
|
|
As soon as you hit WaitAll, you are telling the system to wait for the tasks to complete somehow. This means you're going to have to cancel the task from inside the running task - which is why I put it inside the running task.
This space for rent
|
|
|
|
|
So, may i use Thread instead? because i can stop it from outside the running code.
|
|
|
|
|
Yes, you can, but you're not buying yourself anything by doing so.
You're still going to have to signal the thread to stop and if your code outside the thread is blocked waiting for the thread(s) to finish its/their task(s), how is your outside code going to cancel that thread?
You won't buy yourself an easier solution by using a thread. You end up with the exact same problem, just using different classes.
|
|
|
|
|
I have a label displaying some content in listview item. When a user double clicks the label, it should enable a user to change the listview content.
Check the image here
If user double click the first name (check the image), it should enable a user to change the first name. Is there a simpler way to do this?
Thanks!
|
|
|
|
|
Looks like this[^] CP article might help you.
"You'd have to be a floating database guru clad in a white toga and ghandi level of sereneness to fix this goddamn clusterfuck.", BruceN[ ^]
|
|
|
|
|
lllllllllllllllllllllllll
modified 6-Jan-16 12:26pm.
|
|
|
|
|
WHAT? You're question made no sense at all and, without any context information, is impossible to figure out what you're talking about.
All anyone knows is that you have a Windows Forms application and you're having some kind of problem with what appears to be the OpenFile dialog.
|
|
|
|
|
Maybe take Dictionary and see what PREVIOUS OPEN.
|
|
|
|
|
Calm down. Like others, I have read your original post and don't really understand what you are asking for. Now, I appreciate that you aren't a native English speaker, so the terms you are using might not be exactly what you think they mean. When you talk about previous open, are you talking about a form that has been closed and that you are loading again? Is it a window that's already open and you have Control-Tabbed to get to it?
This space for rent
|
|
|
|
|
I think - but I'm not sure - that he is processing a file and then when his code tries to do something with it again, it locks up. If so, Nathan is probably right that he isn't closing and disposing of streams / handles but without relevant code...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|