Question

Good night.

I´m novate in 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?

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;
        }
    }
Was it helpful?

Solution

In order to insert the value into the database

1) Create a insert_Categoria method in the .xsd file (which includes insert query)

2) Include the insert query in your class (cad) for example

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

 Cad Categoria = new Cad();
 int abc = label1.txt;
 string pqr = text1.txt;
 Categoria.Insert_Categoria(abc,pqr);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top