C#向flowlayoutpanel和数据库添加控件
晚安 我是c#中的新星 我创建了一个类,conexion到数据库,表单需要添加名称来创建按钮并插入数据库 问题:如何将方法添加到flowLayoutPanel1.Controls.add并插入数据库 请帮我解决这个问题 表格C#向flowlayoutpanel和数据库添加控件,c#,.net,flowlayoutpanel,C#,.net,Flowlayoutpanel,晚安 我是c#中的新星 我创建了一个类,conexion到数据库,表单需要添加名称来创建按钮并插入数据库 问题:如何将方法添加到flowLayoutPanel1.Controls.add并插入数据库 请帮我解决这个问题 表格 public partial class Form1 : Form { private void Form1_Load(object sender, EventArgs e) { } private void Adc_Clic
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 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) 在.xsd文件(包括插入查询)中创建插入方法 2) 例如,在类(cad)中包含插入查询
public int Insert_Categoria(Int64 pId, String pCategoria)
{
return Adapter.Insert(pId,pCategoria);
}
3) 例如,在.aspx.cs文件中包含带有对象的insert查询
Cad Categoria = new Cad();
int abc = label1.txt;
string pqr = text1.txt;
Categoria.Insert_Categoria(abc,pqr);