|
I have a DataGridView in which there are 4 columns; Reference,Quantity, Rate and Amount.
The DataGridView is Editable. When I enter a value in the Reference Column then immediately it will fill the other values in the others cells from mysql database.
This is what I tried....
private void TAB_Credit_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
try
{
if (TAB_Credit.CurrentCell.ColumnIndex == 0)
{
MySqlDataAdapter sa = new MySqlDataAdapter("SELECT * FROM table WHERE Reference='" + TAB_Credit.Rows[e.RowIndex].Cells["Reference"].Value + "'", MyConnexion);
DataTable dt2 = new DataTable();
sa.Fill(dt2);
double value = (double)TAB_Credit.Rows[e.RowIndex].Cells["Quantite"].Value * (double)TAB_Credit.Rows[e.RowIndex].Cells["PU"].Value;
TAB_Credit.Rows[e.RowIndex].Cells["Designation"].Value = dt2.Rows[0]["Designation"].ToString();
TAB_Credit.Rows[e.RowIndex].Cells["Quantite"].Value = dt2.Rows[0]["Quantite"].ToString();
TAB_Credit.Rows[e.RowIndex].Cells["PU"].Value = dt2.Rows[0]["Prix_Unitaire"].ToString();
TAB_Credit.Rows[e.RowIndex].Cells["Total"].Value = value.ToString();
}
}
catch
{ }
}
So in the datagrid, when I insert in the Reference Cell nothing is appearing in the other cells.
Thank you.
|
|
|
|
|
Get rid of the try-catch. You are swallowing any exceptions that are being raised which is very, very bad practice.
Also never, ever use string concatenation with user-entered information to create sql commands - you are leaving yourself wide open to SQL Injection attacks - see Query Parameterization Cheat Sheet - OWASP[^]
Make those two changes and see what happens. If there is an error reported let us know what it is.
|
|
|
|
|
Do not repost you have already posted this in C# questions.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
i want to create point and move it from point to another point on picturebox in time
i want this code in c#
|
|
|
|
|
Member 13154038 wrote: i want this code in c# Then you will need to write it; this site does not provide code to order.
|
|
|
|
|
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
When I finished serialize and Deserialize,and create a local file .
But if i need update code, i create a new variable in SerializationInfo ,for example ,I declare a new variable "A" in code. But when i deserialize exist old local file, the exception warning is "can not find A", so Deserialize failed. How can i do if i want to ignore A when deserialize old files?
|
|
|
|
|
It depends how your deserialisation is working, but basically you need something in the file to tell you which version the contents were created with.
|
|
|
|
|
how to do it? I don't know how to do....Could u send me an example?
|
|
|
|
|
Example of what? I have no idea what your code is doing or how you are managing your data. Just think about what you are trying to do. If you change the definition of a class after it is serialised, then the data will no longer match. So you need some way to use the previous definition to deserialise it. How you achieve this will depend a lot on the structure of your data and the associated classes.
|
|
|
|
|
Yes, but i have no idea to achieve it...Could u help me?
For example,
Class A
{
int a=0;
int b=0;
}
When i finished serialise class A and create a local file "Saved".
When i update my Class A
Class A
{
int a=0;
int b=0;
int c=0;
}
Then deserialise "Saved", it will throw exception ,how can i do it? I hope when i deserialize "Saved",it will ignore c.
|
|
|
|
|
You cannot do it with the new class, because it does not match. You must deserialize into an instance of the old class and then copy the data to the new one.
[edit]
If the new version of your class is actually based on the original you may be able to do it that way using a cast. Should be easy to test.
[/edit]
|
|
|
|
|
Oh, actually, my Class is a form , i use serilized to store input data, like textbox or radiobutton data.
When my project version update, maybe i will add some textbox or other controls in form class, so i will not deserilize old file, i don't know how to handle it.
Please tell me a method to realize save function.
|
|
|
|
|
You probably need to write a custom serialiser.
|
|
|
|
|
Please help i am new to C# and i have a windows form with textbox1, textbox2, and buttom1 i would like to print the value of textbox1 without previewing or let me say straight to the printer without any interactions, textbox value has to be the number of capies i would love to print and also to page number all those copies say if i input 3 it should say page 1/3 2/3 3/3 please help and excuse my english i have the following code under my button
private void button1_Click(object sender, EventArgs e)
{
PrintDocument printDocument = new PrintDocument();
printDocument.DefaultPageSettings.Landscape = true;
printDocument.DefaultPageSettings.PaperSize = new PaperSize("zed", 400, 850 );
//printDocument.PrinterSettings.Copies = 2;
printDocument.PrintPage += PrintDocumentOnPrintPage;
printDocument.Print();
|
|
|
|
|
Hello all,
I have a (personal) screensaver that shows particular content based on what applications are running. Under Win10 the program runs perfectly when executed directly (ie. running the exe), however when the program is executed from Windows10 (via screensaver trigger) the application can no longer enumerate Process windows.
Specifically:
If i use the following code snippet:
using System.Diagnostics;
Process[] processlist = Process.GetProcesses();
foreach (Process process in processlist)
{
if (!String.IsNullOrEmpty(process.MainWindowTitle))
{
Console.WriteLine("Process: {0} ID: {1} Window title: {2}", process.ProcessName, process.Id, process.MainWindowTitle);
}
}
and run the application I get a proper list of open windows. But if the SAME application is launched as a screensaver, the above code produces nothing. Never had this issue under Win7 or previous.
Does anyone have any idea what might be happening ?
Thanks in advance,
Andy
|
|
|
|
|
Disclaimer; I never touched Win10 - but it may just be running as another user. Something like the SYSTEM account, with limited rights.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for the reply. I checked and SYSTEM has full admin privledges. I even changed and made sure that the app had FULL access as either myself or SYSTEM. Same effect.
(It's hard doing a google search on this because you get a zillion hits for "how to change your screensaver" LOL)
Still stuck ...
Andy
|
|
|
|
|
Your only recourse is to add debug/logging code to the screensaver to find out what is going on when it runs for real.
|
|
|
|
|
andymo2 wrote: I checked and SYSTEM has full admin privledges. Great. Format your box, or throw it away - SYSTEM is a limited account for a reason.
Another scenario where this would fail would be if the screensaver (or the OS) opens a new desktop. You may not have enumerate-priviliges there, and it may not have any open windows.
Is there error-logging included in the code? Iow, are you sure there is no exception thrown that terminates the execution of the screensaver?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
As Eddy said, I think your screensaver is running in a different desktop:
By default, there are three desktops in the interactive window station: Default, ScreenSaver, and Winlogon.
...
Whenever a secure screen saver activates, the system automatically switches to the ScreenSaver desktop, which protects the processes on the default desktop from unauthorized users.
According to a comment on this 2006 blog post from Raymond Chen[^], if you tick the "on resume display log-on screen" option, your screensaver will be run in "secure" mode.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you for all the responses.
I don't have "on resume display log-on screen" checked. However it seems like it might be something like a separate desktop (I never knew!)
.
I re-coded the screensaver so that when it runs it only fills half of the screen. The idea was so I can get a look at the task manager and see what user/owner the program was running under (because I can't usually see it when it is running obviously).
Some observations:
- the screensaver runs correctly when activated by the "preview" button in the screen saver management dialog. It gets the enumeration of windows, and it only fills half the screen and I can read the task manager.
- when triggered by the OS after being idle, the program correctly only fills half of the screen but the rest is black and the rest of the desktop is gone.
So how can I get this desktop to be able to see what programs are running ? It is able to read from the HDD and other parts of screensaver that work.
This has worked for years on Windows 7 and 8, and I am only an intermediate C# coder. Frustrating.
|
|
|
|
|
andymo2 wrote: he screensaver runs correctly when activated by the "preview" button in the screen saver management dialog.
That's because when the screen saver is launched from that dialog, it's running as YOU, not the system.
andymo2 wrote: when triggered by the OS after being idle, the program correctly only fills half of the screen but the rest is black and the rest of the desktop is gone.
That would be because you're looking as the secured desktop screen savers run under.
andymo2 wrote: So how can I get this desktop to be able to see what programs are running
You don't. That desktop hjas been secured to the point where anything running under it cannot see the processes running under a different desktop, namely the users desktop logged into the console.
andymo2 wrote: It is able to read from the HDD and other parts of screensaver that work.
Yes, a screen saver running on the screen saver desktop still has access to other system resources, such as the local drives.
|
|
|
|
|
|
Why even bother with a "screen saver"?
Any program running "full-screen" (or not) will meet your requirements (based on your description).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|