Obecnie jestem tworzenia i czytania DataTable z następującego kodu w moim Page_LoadJak wypełnić DataTable z SQL tabeli
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;
}
}
chciałbym wiedzieć jak przerobić ten kod tak, że czyta z kwerendy SQL ? Eksperymentuję z poniższym kodem, ale nie jestem pewien, jak je połączyć, aby dane podlegające obciążeniu strony wypełniały się poniższym poleceniem 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);
}
gdzie jesteś zatrzymany? Która linia? –
ta tabela liniowa = (DataTable) Session ["AllFeatures1"]; Chciałbym, żeby to była t1 = (DataTable) Sesja ["AllFeatures1]; – AhabLives
Więc co cię powstrzymuje." Znasz kod –