我目前建立在我的Page_Load閱讀下面的代碼的DataTable如何填寫數據表與SQL表
protected void Page_Load(object sender, EventArgs e)
{
if (Session["AllFeatures1"] == null)
{
Session["AllFeatures1"] = GetData();
}
table = (DataTable)Session["AllFeatures1"];
DayPilotCalendar1.DataSource = Session["AllFeatures1"];
DayPilotNavigator1.DataSource = Session["AllFeatures1"];
if (!IsPostBack)
{
DataBind();
DayPilotCalendar1.UpdateWithMessage("Welcome!");
}
if (User.Identity.Name != "")
{
Panel1.Visible = true;
}
}
我想知道如何將這個代碼,以便它從一個SQL查詢讀取轉換?我正在試驗下面的代碼,但我不知道如何連接它們,以便我的頁面加載中的數據表格填充下面的SQL命令。
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["BarManConnectionString"].ConnectionString);
conn.Open();
string query = "SELECT * FROM [EventOne]";
SqlCommand cmd = new SqlCommand(query, conn);
DataTable t1 = new DataTable();
using (SqlDataAdapter a = new SqlDataAdapter(cmd))
{
a.Fill(t1);
}
你在哪裏卡住了?哪條線? – 2012-08-16 18:27:28
this line table =(DataTable)Session [「AllFeatures1」]; 我希望它是t1 =(DataTable)Session [「AllFeatures1]; – AhabLives 2012-08-16 18:32:01
那麼什麼是阻止你的?你知道代碼 – 2012-08-16 18:38:36