Paste "Otomatik Sql Değer Insert..." C#
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WinDeneme
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19.  
  20.  
  21. public class Degerler
  22. {
  23. public string adi { get; set; }
  24. }
  25.  
  26. private String GenerateSqlString(IEnumerable<Degerler> ransaat)
  27. {
  28. var res = ransaat.GroupBy(u => u.adi).ToList();
  29. var str = new String[res.Count];
  30.  
  31. int i = 0;
  32.  
  33. foreach (var re in res)
  34. {
  35. str[i] = String.Concat((char)39, re.Key, (char)39);
  36. i++;
  37.  
  38. }
  39. return string.Join(",", str);
  40. }
  41.  
  42. private void Form1_Load(object sender, EventArgs e)
  43. {
  44.  
  45. }
  46.  
  47. private void button1_Click(object sender, EventArgs e)
  48. {
  49. Degerler ad1 = new Degerler();
  50. ad1.adi = "mesut";
  51.  
  52. Degerler ad2 = new Degerler();
  53. ad2.adi = "hasan";
  54.  
  55. Degerler ad3 = new Degerler();
  56. ad3.adi = "ahmet";
  57.  
  58.  
  59. List<Degerler> rnd = new List<Degerler>();
  60. rnd.Add(ad1);
  61. rnd.Add(ad2);
  62. rnd.Add(ad3);
  63.  
  64. var snc = GenerateSqlString(rnd);
  65.  
  66. string insh="INSERT INTO VALUES("+ snc.ToString()+")";
  67.  
  68. textBox1.AppendText(snc.ToString()+"\n");
  69. textBox1.AppendText(insh);
  70. }
  71. }
  72. }
  73.  
  74. //'mesut','hasan','ahmet'
  75. //INSERT INTO VALUES('mesut','hasan','ahmet')
  76.  
Submitted and never expires    Report abuse
2KB Characters: 1524 Hits: 98