請嘗試以下:
SqlConnection conobj;
protected void Page_Load(object sender, EventArgs e)
{
conobj = new SqlConnection();
string connestring = System.Configuration.ConfigurationManager.ConnectionStrings["YOURCONNECTIONSTRING"].ConnectionString;
conobj.ConnectionString = connestring;
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = conobj;
cmd.CommandText = "Select * from YOURTABLE";
conobj.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
conobj.Close();
}
請提供代碼C#和SQL所以這可以得到回答 – 2012-02-22 03:22:09