Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to Install Windows OS On selected IP's In a Network Pin
Dave Kreskowiak5-Apr-15 4:16
mveDave Kreskowiak5-Apr-15 4:16 
AnswerRe: How to Install Windows OS On selected IP's In a Network Pin
Dave Kreskowiak5-Apr-15 3:58
mveDave Kreskowiak5-Apr-15 3:58 
GeneralRe: How to Install Windows OS On selected IP's In a Network Pin
OriginalGriff5-Apr-15 5:39
mveOriginalGriff5-Apr-15 5:39 
GeneralRe: How to Install Windows OS On selected IP's In a Network Pin
Dave Kreskowiak5-Apr-15 5:43
mveDave Kreskowiak5-Apr-15 5:43 
GeneralRe: How to Install Windows OS On selected IP's In a Network Pin
OriginalGriff5-Apr-15 5:57
mveOriginalGriff5-Apr-15 5:57 
QuestionHow to extract XMLElement of selectedItem of ListBox in WPF? Pin
ShanmugaKS4-Apr-15 12:18
ShanmugaKS4-Apr-15 12:18 
AnswerRe: How to extract XMLElement of selectedItem of ListBox in WPF? Pin
Richard Deeming7-Apr-15 2:18
mveRichard Deeming7-Apr-15 2:18 
QuestionSelect element from a List<> Pin
DPaul19944-Apr-15 8:38
DPaul19944-Apr-15 8:38 
I have two buttons (button1 and button2), a List<int> and a database. When form is loading, it selects a row from database with some values and assign them value to some labels and int variables. When I click on button1, the id of the row is inserted in list as an int value (idintrebare). In List can be maximum 26 elements. Here is my problem: when I click on button2, I want to select from database, rows where idintrebare is equal with id field from table (questions), but only one row per click, and assing to the same labels and int variables values from table. If all elements from list were selected, application will exit. Here is what I tried:
First I have the list:
C#
List<int> coada = new List<int>(26);
Function for select data:
C#
private void selectCoada()
        {
            using (Conexiune.getConnection())
            {
                    foreach (int idi in coada)
                    {
                        string select = "SELECT DISTINCT * FROM questions WHERE id = '" + idi + "' LIMIT 1";
                        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"];
                                idintrebare = Convert.ToInt32(rdra["id"]);
                                SimulatorManager.Intrebare = textBox1.Text;
                            }
                        }
                        catch (InvalidOperationException ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
            }
        }

In button1 I have just:
C#
coada.add(idintrebare);
In button2 I have:
C#
selectCoada();
The problem is that it selects only one value from list. I tried to use a for like this:
C#
private void selectCoada()
        {
            using (Conexiune.getConnection())
            {
                for(int i=0;i<=coada.Count;i++) {
                    foreach (int idi in coada)
                    {
                        string select = "SELECT DISTINCT * FROM questions WHERE id = '" + idi + "' LIMIT 1";
                        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"];
                                idintrebare = Convert.ToInt32(rdra["id"]);
                                SimulatorManager.Intrebare = textBox1.Text;
                            }
                        }
                        catch (InvalidOperationException ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
, but also didn't worked.
AnswerRe: Select element from a List<> Pin
BillWoodruff4-Apr-15 9:30
professionalBillWoodruff4-Apr-15 9:30 
GeneralRe: Select element from a List<> Pin
DPaul19944-Apr-15 10:38
DPaul19944-Apr-15 10:38 
GeneralRe: Select element from a List<> Pin
DPaul19944-Apr-15 10:45
DPaul19944-Apr-15 10:45 
GeneralRe: Select element from a List<> Pin
DPaul19944-Apr-15 11:14
DPaul19944-Apr-15 11:14 
GeneralRe: Select element from a List<> Pin
BillWoodruff4-Apr-15 11:17
professionalBillWoodruff4-Apr-15 11:17 
GeneralRe: Select element from a List<> Pin
DPaul19945-Apr-15 0:48
DPaul19945-Apr-15 0:48 
GeneralRe: Select element from a List<> Pin
BillWoodruff5-Apr-15 1:48
professionalBillWoodruff5-Apr-15 1:48 
GeneralRe: Select element from a List<> Pin
DPaul19945-Apr-15 3:08
DPaul19945-Apr-15 3:08 
GeneralRe: Select element from a List<> Pin
BillWoodruff5-Apr-15 10:12
professionalBillWoodruff5-Apr-15 10:12 
GeneralRe: Select element from a List<> Pin
DPaul19945-Apr-15 10:16
DPaul19945-Apr-15 10:16 
SuggestionRe: Select element from a List<> Pin
Richard Deeming7-Apr-15 2:21
mveRichard Deeming7-Apr-15 2:21 
GeneralRe: Select element from a List<> Pin
DPaul19947-Apr-15 6:43
DPaul19947-Apr-15 6:43 
Questionneed to order a file in stream read and write c# Pin
Member 115700984-Apr-15 7:31
Member 115700984-Apr-15 7:31 
AnswerRe: need to order a file in stream read and write c# Pin
PIEBALDconsult4-Apr-15 8:03
mvePIEBALDconsult4-Apr-15 8:03 
GeneralRe: need to order a file in stream read and write c# Pin
Member 115700984-Apr-15 8:26
Member 115700984-Apr-15 8:26 
QuestionC# class constructor best practice ? Pin
BillWoodruff4-Apr-15 5:05
professionalBillWoodruff4-Apr-15 5:05 
GeneralRe: C# class constructor best practice ? Pin
PIEBALDconsult4-Apr-15 5:52
mvePIEBALDconsult4-Apr-15 5:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.