0

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;
        }
    }

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.