2013-10-19 41 views
0

晚安。C#將控制添加到flowlayoutpanel和數據庫

我沒有在c#中。

我創建了一個類,conexion對數據庫和表單需要添加名稱創建按鈕並插入到數據庫中。

問題:如何將該方法添加到flowLayoutPanel1.Controls.Add並插入數據庫?

請幫我解決。

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

爲了插入值到數據庫

1)創建在.xsd文件一個insert_Categoria方法(其包括插入查詢)

2)包括插入查詢您的類(CAD),例如

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

3)包含在你的.aspx.cs對象插入查詢文件例如

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

謝謝你這麼很多人:3 – user2792658