Israel

Israel

  • 631
  • 1.3k
  • 217.4k

Its ONLY displaying the last value. Not any values i need...

Dec 31 2019 7:51 AM
Hello,
 
There is a problem. Its filter only the last record.
Why I could not filter any data I want into a column from my textbox.
 
For example, if my column "A" I have:
Xhiami
Steve
Sami
 
When I insert into my textbox the value Steve Its doesn’t transfert this record. But when I write the last word for example Sami. Its shows. Only showing the last value.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Windows.Forms;  
  6. using System.Data;  
  7. using System.Data.SqlClient;  
  8. namespace WindowsFormsApplication1  
  9. {  
  10. public partial class Form1 : Form  
  11. {  
  12. public Form1()  
  13. {  
  14. InitializeComponent();  
  15. }  
  16. SqlConnection conn = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf;Integrated Security = True;Integrated Security = True");  
  17. SqlCommand comm;  
  18. SqlDataAdapter da;  
  19. string connstr = @"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf;Integrated Security = True;Integrated Security = True";  
  20. private void button1_Click(object sender, EventArgs e)  
  21. {  
  22. string myConnectionString;  
  23. myConnectionString = "Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf; Integrated Security = True; Integrated Security = True";  
  24. {  
  25. conn = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf; Integrated Security = True; Integrated Security = True");  
  26. if (conn.State != ConnectionState.Open)  
  27. conn.Open();  
  28. using (var cmd = new SqlCommand())  
  29. {  
  30. cmd.Connection = conn;  
  31. cmd.CommandType = System.Data.CommandType.Text;  
  32. cmd.CommandText = @"INSERT INTO test2 (DATA, A, B, C) SELECT DATA, A, B, C FROM test1 where A ='" + textBox1.Text + "'"; cmd.ExecuteNonQuery(); //On this line  
  33. }  
  34. }  
  35. Console.WriteLine("Done.");  
  36. conn.Close();  
  37. }  
  38. }  
  39. }  

Answers (1)