Goran Bibic

Goran Bibic

  • 482
  • 2.9k
  • 197.2k

Dinamic button create insert into sql function?

Apr 6 2018 3:19 PM
I have created dinamic button from sql items table...I need to create insert into function for them...I create POS system for sale...
 
  1. private void Form1_Load(object sender, EventArgs e)  
  2.        {  
  3.            // TODO: This line of code loads data into the 'bssDataSet.roba_usluge' table. You can move, or remove it, as needed.  
  4.            this.roba_uslugeTableAdapter.Fill(this.bssDataSet.roba_usluge);  
  5.   
  6.   
  7.   
  8.            SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=bss;Integrated Security=True");  
  9.            //SqlCommand cmd = new SqlCommand("SELECT Concat(ime),data FROM roba_usluge", con);  
  10.           // SqlCommand cmd = new SqlCommand("SELECT (redni_broj),data FROM roba_usluge", con);  
  11.            SqlCommand cmd = new SqlCommand("SELECT (ime), data FROM roba_usluge", con);  
  12.           // SqlCommand cmd = new SqlCommand("SELECT Concat(ime, cijena_sa_porezom),data FROM roba_usluge", con);  
  13.   
  14.            // Getting all the data to ItemTable        
  15.            var da = new SqlDataAdapter(cmd);  
  16.            var ItemTable = new DataTable();  
  17.            da.Fill(ItemTable);  
  18.   
  19.            con.Open();  
  20.            Int32 count = ItemTable.Rows.Count;  
  21.            con.Close();  
  22.   
  23.            int top = 50;  
  24.            int left = 50;  
  25.            for (int i = 1; i <= count; i++)  
  26.            // for (int i = 0; i < count; i++)      
  27.            {  
  28.                Button button = new Button();  
  29.                button.Size = new Size(128,128);  
  30.                button.BackColor = Color.Transparent;  
  31.                //button.FlatStyle = FlatStyle.Flat;  
  32.                button.FlatAppearance.BorderSize = 0;  
  33.                button.Font = new System.Drawing.Font("Trebuchet MS", 10);  
  34.                button.TextAlign = ContentAlignment.TopCenter;  
  35.                button.BackgroundImageLayout = ImageLayout.Zoom;  
  36.                  
  37.                button.Left = left;  
  38.                button.Top = top;  
  39.                button.Text = ItemTable.Rows[i - 1][0].ToString();  
  40.                //if (ItemTable.Rows[i - 1][1] != null && ItemTable.Rows[i - 1][1] != "")  
  41.                    if (ItemTable.Rows[i - 1][1] != null)  
  42.                    {  
  43.                    try  
  44.                    {  
  45.                        byte[] _byte = (byte[])ItemTable.Rows[i - 1][1];  
  46.                        MemoryStream ms = new MemoryStream(_byte);  
  47.                        button.BackgroundImage = System.Drawing.Image.FromStream(ms);//bilo image  
  48.                    }  
  49.                    catch { }  
  50.                }  
  51.                // button.Text = ItemTable.Rows[i][0].ToString();      
  52.                this.Controls.Add(button);  
  53.                if (i % 5 == 0)  
  54.                {  
  55.                    left = 50;  
  56.                    top += button.Height + 2;  
  57.                }  
  58.                else  
  59.                {  
  60.                    left += button.Width + 2;  
  61.                }  
  62.                // top += button.Height + 2;      
  63.   
  64.   
  65.            }  
  66.        } 
 

Answers (37)