|
So use the debugger to look at the value of that cell and find out what type of data it contains. When you know that, you can start looking at why it isn't a boolean value.
We can't do that for you: we can't run your code, and don't have your data which fills the table if we could!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
did you have a time to take a look via teamviewr
|
|
|
|
|
Are you clinically insane?
You would allow total strangers you never met to remotely control your PC?
Have you any idea what some of them might do?
Have you ever heard of ransomware?
If you have that enabled, disable it immediately!
Use the debugger.
Look at the cell content. It should tell you a lot.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
no i'm not clinically insane.... but we are in a community to help each author.and i'm stacked.
|
|
|
|
|
We are in a community to help each other, but you have no idea who people are, and what they are going to do. This is the real world, and leaving your machine open for total strangers to access and do whatever they want - and if you give them access to VS that's exactly what they can do - is not "asking for trouble" it's inviting it indoors, giving it a beer, and telling it where you keep your credit cards!
Be realistic and honest: you know how to use the debugger, don't you? (If you don't, then say so and we'll try to get you started. But not telling us relevant information is just wasting your own time, as well as ours)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
many thanks for your advice and your time.
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i get my issue....
i need to get the value from DataGridView that was selected into array.
can you write to me example code.
|
|
|
|
|
Sorry, but I don't understand what you said: remember I only get exactly what you type to work from.
Can you explain in more detail, perhaps?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
i need code for get selected column value from datagridview into array list
//foreach (DataGridViewRow row in this.dataGridView1.Rows)
//{
// if ((((bool)(row.Cells[this.invoiceNO.Index].Value)) == true))
// {
// a.Add(row.Cells[this.invoiceNO.Index].Value);
// }
//}
|
|
|
|
|
The problem is that you aren't thinking about what is going on here: the value you are casting to a bool is not a bool value, so the cast fails: that can't be "fixed" at that point - you need to find out what it actually is and why it isn't the value you are expecting.
And the only way to do that is to use the debugger while your code is running and look at what the actual data looks like. No amount of code I could give you would fix that - because either the index is wrong, the data is wrong, the table isn't organised as you think it is, or it's totally the wrong table.
We can't tell you which of those: but the debugger probably can almost instantly!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
As long as you keep mixing "business logic" in with your "data access" logic, your life will continue to be difficult.
You are simply copying and pasting each "case", without any thought to the amount of duplicate code you are creating.
I would tell you to rewrite what you've got instead of helping you to "fix" it (and continuing to support your bad habits).
Or are you getting paid by lines-of-code?
|
|
|
|
|
Do you know in the Visual Studio programming webcam with standard library to the laptop's webcam ? what's the library name ? if attached great example.
|
|
|
|
|
You can use Google to answer this question, or search MSDN.
|
|
|
|
|
|
I created one table like this:
CREATE TABLE Pitanja
(
ID int NOT NULL IDENTITY (1,1) PRIMARY KEY,
Pitanje nvarchar(1000) NOT NULL,
Odgovor int NOT NULL,
OpcijaA nvarchar(1000) NOT NULL,
OpcijaB nvarchar(1000) NOT NULL,
OpcijaC nvarchar(1000) NOT NULL,
OpcijaD nvarchar(1000) NOT NULL
);
This is one part of table Pitanja
INSERT INTO Pitanja(Pitanje,Odgovor,OpcijaA,OpcijaB,OpcijaC,OpcijaD) VALUES('Blizu kog grada se nalaze Sremski Karlovci',3,'Rume','Sremske Mitrovice','Novog Sada','Šida');
Answers column contains number of correct choice,not word of correct choice.How to check answer when user select one of four choices from four buttons?
|
|
|
|
|
You could put the answers into an array like so:
string[] Answers = new string[4];
string UserChoice = Answers[IndexOfChoice];
Just set the variable IndexOfChoice to a number from 0 to 3 depending upon which button was clicked.
IndexOfChoice is an int.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
 Here is complete code:
int QuesionCount;
int IndexOfChoice;
DataTable dt = new DataTable();
int[] Answers = new int[4];
string cs= @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=c:\users\pavle\documents\visual studio 2015\Projects\Ko zna zna\Ko zna zna\Koznazna.mdf;Integrated Security=True";
private void Form1_Load(object sender, EventArgs e)
{
using (SqlConnection connection = new SqlConnection(cs))
{
string query = "SELECT * FROM Pitanja ORDER BY NEWID()";
SqlCommand command = new SqlCommand(query, connection);
try
{
connection.Open();
dt.Load(command.ExecuteReader());
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
setQuestion();
}
private void provera()
{
int UserChoice = Answers[IndexOfChoice];
if (answer_id == UserChoice)
{
MessageBox.Show("Odgovor je tacan!");
}
else
{
MessageBox.Show("Odgovor nije tacan!");
}
}
private void button1_Click(object sender, EventArgs e)
{
Answers[IndexOfChoice] = 1;
provera();
}
private void button2_Click(object sender, EventArgs e)
{
Answers[IndexOfChoice] = 2;
provera();
}
private void button3_Click(object sender, EventArgs e)
{
Answers[IndexOfChoice] = 3;
provera();
}
private void button4_Click(object sender, EventArgs e)
{
Answers[IndexOfChoice] = 4;
provera();
}
private void button5_Click(object sender, EventArgs e)
{
try
{
this.QuesionCount++;
setQuestion();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
int answer_id;
private void setQuestion()
{
try
{
this.label2.Text = this.dt.Rows[this.QuesionCount]["Pitanje"].ToString();
this.button1.Text = this.dt.Rows[this.QuesionCount]["OpcijaA"].ToString();
this.button2.Text = this.dt.Rows[this.QuesionCount]["OpcijaB"].ToString();
this.button3.Text = this.dt.Rows[this.QuesionCount]["OpcijaC"].ToString();
this.button4.Text = this.dt.Rows[this.QuesionCount]["OpcijaD"].ToString();
this.label3.Text = this.dt.Rows[this.QuesionCount]["Odgovor"].ToString();
answer_id = Convert.ToInt32(this.dt.Rows[this.QuesionCount]["Odgovor"]);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
How to shuffle choises and keep track of the correct solution?
|
|
|
|
|
Who's writing this application, you or us? How do you think you should shuffle the cards?
This space for rent
|
|
|
|
|
I am creating new database.This is one part of it:
{"a1":"Kina","a2":"Berlin","a3":"Živi","a4":"Cigla","a5":["Zid"],"b1":"Rešetke","b2":"Kriminal","b3":"Alkatraz","b4":"Kaucija","b5":["Zatvor"],"c1":"Artiljerija","c2":"Volt","c3":"Naboj","c4":"AA","c5":["Baterija","baterije"],"d1":"Bubreg","d2":"Nadležni","d3":"Tkivo","d4":"Transplantacija","d5":["Organ"],"rr":["Ćelija","ćelijski","celija","celijski"]}
How to make all this as answer inside column Answers: ["Ćelija","ćelijski","celija","celijski"]
modified 26-Dec-16 15:10pm.
|
|
|
|
|
That is not a database. That is a fragment of JSON, and should be treated as such.
This space for rent
|
|
|
|
|
This is one part of text file:
["Koje ostrvo od Italije razdvaja Ligursko more.?",2,"Sicilija","Korzika","Sardinija","Kapri"]
["Agrostologija je nauka o ?",1,"travama","tabletama","konjima","zvezdama"]
["Sin rimskog cara Klaudija i Mesaline zvao se:",2,"Germanik","Britanik","Italik","Hispanik"]
["Šta je ofuro",1,"Japanski običaj","Kineske patike","Otkrivanje","Nemački izraz"]
["Bombardon je:",1,"muzički instrument","veliki top","vrsta aviona","vrsta slatkiša"]
["Koji filozof je rekao \"Sve teče\"?",2,"Pitagora","Heraklit","Aristotel","Sokrat"]
I want to get text from text file between [ and ?
I tried this commands but it doesn't work:
List<string> questions = File.ReadLines(path)
.Where(x => x.StartsWith("[") &&
x.EndsWith("?"))
.ToList();
foreach (string x in questions)
{
listBox1.Items.Add(x);
}
|
|
|
|
|
x does not endwith ? it contains ?
|
|
|
|
|
Look at each line, and use IndexOf and Substring:
string s = @"[""Koje ostrvo od Italije razdvaja Ligursko more.?"",2,""Sicilija"",""Korzika"",""Sardinija"",""Kapri""]";
int start = s.IndexOf('[') + 1;
int end = s.IndexOf('?');
string bitInTheMiddle = s.Substring(start, end - start);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
How to do that for all lines?
|
|
|
|
|