Hello!
Help please, I am new to programming. Here, I can’t understand one thing: when typing a name into a user several times on a textBox dataGridView should output not several times lines but the number of names that were entered on the same line. The code does not work. And how to do it. Thank you very much in advance!

List<User> usn = new List<User>(); conn.Open(); SqlCommand seldb = new SqlCommand("Select * from User where username="+textBox1.text, conn); seldb.ExecuteNonQuery(); SqlDataReader read = seldb.ExecuteReader(); int i=0; int j = 0; while (read.Read() == true) { User ia = new User(); ia.Name = read["name"].ToString(); usn.Add(ia); if (dataGridView1.Rows[j].Cells[1].Value.ToString().Contains(textBox1.Text)) { ia.Count = i; } i++; } conn.Close(); dataGridView1.DataSource = usn; 
  • Maybe the problem is in the query to the database? With Select * you get all the information about the contents, try Select Count(*) - Pyrejkee
  • 2
    First, delete the line seldb.ExecuteNonQuery (); she is obviously superfluous here. Secondly write in Russian clearly what you want? If you do not know Russian well, ask someone to help you with a description of the problem. Third, looking at your code, I can immediately say that the string is i ++; must be at the beginning of the cycle, otherwise Count you will always have 1 less. In the third, Count itself probably means not a quantity, but a sequence number (you need to name the variables correctly so that your code is clear not only to you). In the fourth, I didn’t understand at all what you wanted to say with your condition if - iRumba

0