|
I tried to run the update on form loading and I get the error. It means that the error can be from the form that opens this form? Because I checked there and I have used using for everything and is ok..
|
|
|
|
|
Hmm. And there's nothing database-related happening before that in your code?
Could probably another program be running and accessing the same database? Maybe there's some "zombie"-process of your program still running and keeping a connection to the database alive. See if rebooting Windows solves the issue.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
It's ok, I have found the error! In class cs where I have static void Main() , this is the main class of the project, I have this code:
string selectutilizator = "SELECT * FROM accounts";
using (SQLiteCommand selcom = new SQLiteCommand(selectutilizator, Conexiune.getConnection()))
{
using (SQLiteDataReader read = selcom.ExecuteReader())
{
if (read.HasRows)
{
Application.Run(new Elev());
}
else Application.Run(new Intro());
}
}
But I need this for the program..what is wrong there?
|
|
|
|
|
Yep, that's the problem, most certainly. Application.Run(..) is a blocking call, so the DataReader is alive all the time. Just declare a boolean variable hasRows at the top of this code, assign read.HasRows to it after ExecuteReader(), move the if-else out of the using-blocks and use the boolean variable there instead of the reader.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Yes, you right. Thank you very much! This is the solution:
string selectutilizator = "SELECT * FROM accounts";
bool hasrows=false;
using (SQLiteCommand selcom = new SQLiteCommand(selectutilizator, Conexiune.getConnection()))
{
using (SQLiteDataReader read = selcom.ExecuteReader())
{
if (read.HasRows)
{
hasrows=true;
}
}
}
if (hasrows) Application.Run(new Elev());
else Application.Run(new Intro());
|
|
|
|
|
DPaul1994 wrote: Yes, you right. Thank you very much! You're welcome!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Your code is vulnerable to SQL Injection[^].
NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
private void updateIndex()
{
const string update = "UPDATE questions SET indexrow = @idintrebare WHERE id = @idintrebare";
using (SQLiteCommand comp = new SQLiteCommand(update, Conexiune.getConnection()))
{
comp.CommandType = CommandType.Text;
comp.Parameters.AddWithValue("@idintrebare", idintrebare);
comp.ExecuteNonQuery();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I want to run flash file formats: *.swf in winform (VS2005), the toolbox click on All windows forms and select Choose Items ..., select tab: COM Components, browse and select the area marked "Shockwave Flash Control" , then click Macromedia Flash Object Factory and it was dragging on winform error "Failed to import the ActiveX control. Please ensure it is properly registered" winxpsp3 machine I use, how to register to use the flash file above I do ?
http://imagizer.imageshack.com/img661/3521/XzARIi.jpg
|
|
|
|
|
I miss the logic of the official story that a base constructor is not inherited. If a class is able to call its base constructor (accessible) then why it is said the constructor is not inherited. The logic seems to be based on the fact that a base constructor has to be called explicitly, meaning the compiler will not call it automatically (ignore special cases). But the definition of inheritance is not based on the automatic calling.
modified 22-Apr-15 9:49am.
|
|
|
|
|
|
The question assumes an instance constructor. A static constructor is not meant to be called by any outside code or any other class (derived or not derived), it is called only once by the loader, so the issue of derivation is totally moot for static constructor.
|
|
|
|
|
And my answer applies to instance constructors -- in C#.
|
|
|
|
|
That just sounds wrong.
From the C# 5 lang spec: section 1.6.6.3
The ... constructor (which is like an instance method) ...
Because the constructor is an instance member, it is permitted to access both the ... instance field and the ... static field.
The constructor has access to all of the instance's fields and properties and even instance methods.
Section 1.6.7.1
Unlike other members, instance constructors are not inherited, and a class has no instance constructors other than those actually declared in the class. If no instance constructor is supplied for a class, then an empty one with no parameters is automatically provided.
Section 10.11.1:
If an instance constructor has no constructor initializer, a constructor initializer of the form base() is implicitly provided. Thus, an instance constructor declaration of the form
C(...) {...}
is exactly equivalent to
C(...): base() {...}
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
As I recall, the default base ctor is always called first, at least it is if the base class contains instance properties that need initialization.
|
|
|
|
|
CRobert456 wrote: The logic is based on the fact the a base constructor has to be called explicitly, meaning the compiler will not call it automatically That would mean that all objects (!) would inherit the default constructor. That'd be a bit impractical.
You can add code to call an inherited constructor in your class, even if there's a different signature.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
First, I have a button that calls 2 functions. First function (calculateMedieSim()) makes an operation with two number and the second one (selectData()) selects data from tabel. totalsim = 15 and totalsimyes = 8. The result should be 53,3 but it shows 0 Why?
private void button1_Click(object sender, EventArgs e)
{
selectData();
calculateMedieSim();
}
private void selectData()
{
string select = "SELECT * FROM accounts WHERE id=1";
using (SQLiteCommand cmd = new SQLiteCommand(select, Conexiune.getConnection()))
{
using (SQLiteDataReader read = cmd.ExecuteReader())
{
if (read.Read())
{
totalsim = (int)read["totalsim"];
totalsimyes = (int)read["totalsimyes"];
}
}
}
}
private void calculateMedieSim()
{
medie_sim = (totalsimyes / totalsim) * 100;
sansa_examen = Math.Round(medie_sim, 2);
Console.WriteLine(sansa_examen);
}
|
|
|
|
|
the only thing I see wrong is (and I presume you've defined the variables this way as well) ...
totalsim = (int)read...
totalsimyes = (int)read...
so, using integer math, whats going to happen when you divide 8 by 15, hmmmm ?
|
|
|
|
|
those 2 variables are defined by int type
|
|
|
|
|
defined by int type ? yes, because you've defined them as such - define them as double for example
|
|
|
|
|
Aaaa yes, there was the problem. Thanks
|
|
|
|
|
If I change code to:
medie_sim = (totalsim / totalsimyes) * 100;
medie_sim = Math.Round(medie_sim, 2);
Console.WriteLine(medie_sim);
I get 100
|
|
|
|
|
how is medie_sim defined ? let me guess - also an Int ?
|
|
|
|
|