15,921,577 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by DPaul1994 (Top 27 by date)
DPaul1994
31-Mar-15 5:44am
View
It works with 0..I get it now. Thank you very much for your help and time!
DPaul1994
31-Mar-15 5:41am
View
Interesting, it worked..so I have to assing the value -1?
DPaul1994
31-Mar-15 5:27am
View
Hmm I don't really understand, how it can be the same variable? `rows` is total rows that is never modified and `currentrow` is the current id for each row.
DPaul1994
31-Mar-15 4:58am
View
Well I kinda modify the code now. select() function looks like this:
private void select()
{
using (Conexiune.getConnection())
{
string select = String.Format("SELECT * FROM questions WHERE id > {0} ORDER BY id ASC LIMIT 1",rows);
SQLiteCommand cmd = new SQLiteCommand(select, Conexiune.getConnection());
cmd.CommandType = CommandType.Text;
SQLiteDataReader rdra = cmd.ExecuteReader(CommandBehavior.CloseConnection);
try
{
while (rdra.Read())
{
textBox1.Text = rdra["question"].ToString();
textBox2.Text = rdra["answer1"].ToString();
textBox3.Text = rdra["answer2"].ToString();
textBox4.Text = rdra["answer3"].ToString();
r1 = (int)rdra["option1"];
r2 = (int)rdra["option2"];
r3 = (int)rdra["option3"];
currentrow = Convert.ToInt32(rdra["id"]);
SimulatorManager.Intrebare = textBox1.Text;
label11.Text = currentrow.ToString();
}
}
catch (InvalidOperationException ex)
{
MessageBox.Show(ex.Message);
}
}
}
Is ok now?
DPaul1994
31-Mar-15 4:49am
View
Is ok, I know what's the problem. `rows` value is always 1, is not passing to the next row. This is the error. query is the problem I guess or something before that while or in while..
DPaul1994
31-Mar-15 3:51am
View
Hmm something's wrong, it replace the value of rows with each id one by one, but on first selection, it doesn't get out of the while until it selects all rows..and that's wrong. it should select every row one by one but only when button is clicked. Don't know if it matters, but select() is also called at form Load, as initializing first value. Then, each time when button is pressed, it should called again select() function for next row
DPaul1994
31-Mar-15 3:42am
View
1, it means it reads first row. but it doesn't continue with next rows
DPaul1994
31-Mar-15 3:30am
View
I have 2 records with id 1 and 2 :)
DPaul1994
31-Mar-15 2:44am
View
Aaaa you're right, sorry. Well, I did that and I saw the problem. So, select() function is called by a button. Each time when button is pressed, select should select from table next row. And if I click again, it doesn't step into while, is jumping over while, but I don't know why..
DPaul1994
31-Mar-15 2:36am
View
Everything seems to be ok..
DPaul1994
31-Mar-15 2:34am
View
Of course, I check this now
DPaul1994
31-Mar-15 2:27am
View
Aaa sorry, I have a previous error. I don't receive any error messages, is just, it selects only first row
DPaul1994
31-Mar-15 2:18am
View
Is just a var that I will have to use it later in program. Still got this problem...interesting
DPaul1994
31-Mar-15 2:08am
View
I receive "Specified cast is not valid" and I don't understand why. `id` is an integer in table and `rows` is an int initialized with 0
DPaul1994
31-Mar-15 1:17am
View
If I remove LIMIT 1, nothing changes
DPaul1994
31-Mar-15 1:16am
View
I want all rows, one by one
DPaul1994
31-Mar-15 1:16am
View
Exactly!
DPaul1994
29-Mar-15 13:09pm
View
Omg Smile | :) ) It worked. I will try to learn and understand this way to update with DataTable. Thank you for your patience and wish you the best!
DPaul1994
29-Mar-15 11:15am
View
What you did there is just an example of how I could do it, right? Cause is not what I have to do. First I have to collect and compare, then I have to update, you get that, right? No, I don't close them..connection is always opened. I try that now
DPaul1994
29-Mar-15 10:40am
View
I don't know if it matters, but I have another function which select some data and is called on load form. (using SQLiteDataReader)
DPaul1994
29-Mar-15 10:33am
View
Well, is not about I give up, I'm sick of this update :)) I tried to change the code in so many ways, but without success. This is my last try. I get the same error. I tried to close and reopen connection, than close is again, but with no succees. I tried with DataAdapter, with DataReader but it didn't work. I don't know to else to try. And I have to change only a value from a single row, don't understand why to use foreach loop..
<pre lang="c#">
private void UpdateTotalSim()
{
using (SQLiteCommand cmd = new SQLiteCommand(@"update accounts set totalsim=totalsim+1 where username='" + SimulatorManager.Utilizator + "'", Conexiune.getConnection()))
{
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void button4_Click(object sender, EventArgs e)
{
if (check1.Checked == true) result1 = 1;
else result1 = 0;
if (check2.Checked == true) result2 = 1;
else result2 = 0;
if (check3.Checked == true) result3 = 1;
else result3 = 0;
string collect = "Select option1,option2,option3 from questions where `question`='" + SimulatorManager.Intrebare + "'";
SQLiteCommand comp = new SQLiteCommand(collect, Conexiune.getConnection());
comp.CommandType = CommandType.Text;
SQLiteDataReader read = comp.ExecuteReader(CommandBehavior.CloseConnection);
try
{
while (read.Read())
{
int op1 = (int)read["option1"];
int op2 = (int)read["option2"];
int op3 = (int)read["option3"];
if (check1.Checked == false && check2.Checked == false && check3.Checked == false)
MessageBox.Show("Selectati minim o optiune");
else
{
if ((result1 == op1) && (result2 == op2) && (result3 == op3))
{
corect++;
label4.Text = corect.ToString();
check1.Checked = false;
check2.Checked = false;
check3.Checked = false;
select();
}
else
{
incorect++;
label6.Text = incorect.ToString();
check1.Checked = false;
check2.Checked = false;
check3.Checked = false;
select();
}
if (corect + incorect == 1)
{
MessageBox.Show("Test terminat!");
if (corect == 1)
{
UpdateTotalSim(); // HERE I CALL THE UPDATE FUNCTION
MessageBox.Show("Bravo!");
}
else
{
MessageBox.Show("Bleah");
}
this.Close();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
</pre>
DPaul1994
29-Mar-15 9:48am
View
I didn't succeed to fix it. If you can write the code so I can see exactly what are you talking about, it's ok, else that's it. Thank you anyway for your time :)
DPaul1994
28-Mar-15 10:09am
View
Ok, I'll try this :)
DPaul1994
28-Mar-15 9:15am
View
So, using SQLiteCommand, inside this - using SQLiteDataReader - using SQLiteDataAdapter and here is the table?
DPaul1994
28-Mar-15 8:35am
View
Well this may be a silly answer, but that is the entire code :))) I don't really know how to use datatable..yeah :))
DPaul1994
28-Mar-15 8:26am
View
OMG! =)))) Yeah, sorry for that. But database is still locked.
DPaul1994
28-Mar-15 8:01am
View
You mean like that?
using (SQLiteDataAdapter update = new SQLiteDataAdapter("update totalsim from accounts set totalsim=totalsim+1 where username = 'DPaul'", Conexiune.getConnection()))
{
DataTable updt = new DataTable();
update.Fill(updt);
}
Cause I tried this and I receive:
SQL logic error or missing database near 'from': syntax error
Show More