日期:2014-05-17 浏览次数:20512 次
public void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
SqlDataAdapter da = new SqlDataAdapter("select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '" + DropDownList1.Text + "'", con);
DataTable tb = new DataTable();
da.Fill(tb);
con.Close();
for (int i = 1; i <= tb.Rows.Count; i++)
{
TextBox tx = new TextBox();
tx.ID = "textbox" + i.ToString();
Panel1.Controls.Add(tx);
}
}
protected void Button5_Click1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=(Local);database=hdb;uid=sa;pwd=sa@123");
con.Open();
string[] tb = new string[]{};
for (int i = 1; i <= Panel1.Controls.Count; i++)
{
TextBox t = (TextBox)Panel1.FindControl("textbox[" + i + "]");
tb[i] = t.Text.ToString();
}
string sql = string.Format("insert into dbo." + DropDownList1.Text + " values('" + tb[i] + "')", string.Join(",", tb.ToString()));
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
}
foreach (string c in tb)
{
values += (string.IsNullOrEmpty(values) ?&nbs