简体   繁体   English

C#将控件添加到flowlayoutpanel和数据库

[英]C# Adding controls to flowlayoutpanel and database

Good night. 晚安。

I´m novate in c#. 我正在用C#进行创新。

I created one class,conexion to database and form need add the name to create button and insert in database. 我创建了一个类,对数据库和表单进行了转换,需要添加名称创建按钮并插入数据库。

Problem : How add the method to flowLayoutPanel1.Controls.Add and insert to database? 问题 :如何将方法添加到flowLayoutPanel1.Controls.Add并将其插入数据库?

please help me with the solution. 请帮我解决。

Form 形成

public partial class Form1 : Form
    {
 private void Form1_Load(object sender, EventArgs e)
        {

        }

 private void Adc_Click(object sender, EventArgs e)
        {
                Cad Categoria = new Cad();
                    Categoria.Categoria = Adicionartxt.Text; //here comes with the button name, need textbox receives the name and create a button with the name of the textbox.
                    flowLayoutPanel1.Controls.Add(Categoria.Categoria); //problem is here,  

                    int resultado = CategoriaDAL.AddCategoria(Categoria);

                    Adicionartxt.Clear();

                    Adicionartxt.Visible = false;

            }

Class

class Cad
    {
        public Int64 Id { get; set; }
        public String Categoria {get; set;}

        public Cad() { }

        public void Cad(Int64 pId, String pCategoria)
        {
            this.Id = pId;
            this.Categoria = pCategoria;
        }
    }

In order to insert the value into the database 为了将值插入数据库

1) Create a insert_Categoria method in the .xsd file (which includes insert query) 1)在.xsd文件中创建一个insert_Categoria方法(包括插入查询)

2) Include the insert query in your class (cad) for example 2)例如在班级(cad)中加入插入查询

public int Insert_Categoria(Int64 pId, String pCategoria)
{
    return Adapter.Insert(pId,pCategoria);
}

3) Include the insert query with the object in your .aspx.cs file for example 3)例如,将插入查询与.aspx.cs文件中的对象一起包括

 Cad Categoria = new Cad();
 int abc = label1.txt;
 string pqr = text1.txt;
 Categoria.Insert_Categoria(abc,pqr);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM