我目前建立在我的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