using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(
"Data Source=PTZ1\\SQLEXPRESS;Initial Catalog = test; Integrated Security=SSPI;User ID=sa; [email protected]; Trusted_Connection=True;");
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter();
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from testing", conn);
adapter.SelectCommand = cmd;
adapter.Fill(ds, "First Table");
foreach (DataTable tables in ds.Tables)
{
ListBox1.Items.Add(tables.TableName);
}
conn.Close();
}
catch (Exception ex)
{
Label1.Text = "Error in execution " + ex.ToString();
}
}
顯示它,我有以下程序在那裏我從表中讀取數值,並希望在顯示文本字段的表值按鈕點擊。現在當我點擊按鈕時,它只是在列表框中繼續顯示第一張表。
有人可以指導我通過我的錯誤嗎?
謝謝!像魅力一樣工作! – Esha