|
|
|
ASP.NET C# มัน error ครับ ช่วยดูให้หน่อยครับ งานเร่งครับ |
|
|
|
|
|
|
|
อันนี้โค้ดทั้งหมดครับ
Code (C#)
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Import Namespace="System.Web.UI.HtmlControls"%>
<%@ Import Namespace="System.Web.UI.WebControls"%>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts"%>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.Collections"%>
<%@ Import Namespace="System.Configuration"%>
<%@ Import Namespace="System.Web.UI.WebControls.WebParts"%>
<%@ Import Namespace="System.Linq"%>
<%@ Import Namespace="System.Web"%>
<%@ Import Namespace="System.Web.Security"%>
<%@ Page Language="C#" Debug="true" %>
<script runat="server">
SqlConnection objConn = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
String strConnString;
string term1, term_year1;
DataSet ds = new DataSet();
public void Page_Load(object sender, EventArgs e)
{
String strConnString;
strConnString = "Server=MONOJA-PC\\SQLEXPRESS;UID=sa;PASSWORD=1234;database=mydatabases;Max Pool Size=400;Connect Timeout=600;";
objConn = new SqlConnection(strConnString);
objConn.Open();
this.Button2.Enabled = false;
BindData();
}
void BindData()
{
String sql_ct, sql_course, sql_teacher, sql_termyear, sql_term,sql_dc,sql_ct1;
SqlDataReader dtReader, dtReader1,dtReader2;
int intNumRows;
sql_ct = "SELECT count(*) FROM course_teach where id_teacher='" + Session["id_teacher"] + "'";
objCmd = new SqlCommand(sql_ct, objConn);
intNumRows = Convert.ToInt32(objCmd.ExecuteScalar());
if (intNumRows > 0)
{
sql_term = "SELECT term, term_year FROM course order by term_year desc, term desc";
objCmd = new SqlCommand(sql_term, objConn);
dtReader = objCmd.ExecuteReader();
dtReader.Read();
string term = dtReader["term"].ToString();
string termyear = dtReader["term_year"].ToString();
this.lblTerm.Text = term;
this.lblTerm_year.Text = termyear;
dtReader.Close();
dtReader = null;
SqlConnection cnn = new SqlConnection("Server=MONOJA-PC\\SQLEXPRESS;UID=sa;PASSWORD=1234;database=mydatabases;Max Pool Size=400;Connect Timeout=600;");
SqlDataAdapter cmd1 = new SqlDataAdapter("select distinct id_course,name_course,term,term_year from course where term='" + term + "' and term_year='" + termyear + "' order by term_year desc,term desc", cnn);
cmd1.Fill(ds, "course");
SqlDataAdapter cmd2 = new SqlDataAdapter("SELECT * FROM course_teach,course WHERE course.code_course=course_teach.code_course and course_teach.id_teacher = '" + Session["id_teacher"] + "'and course.term_year = '" + termyear + "' and course.term ='" + term + "' order by section", cnn);
cmd2.Fill(ds, "course1");
SqlDataAdapter cmd3 = new SqlDataAdapter("select * FROM style_test", cnn);
cmd3.Fill(ds, "course2");
//this.lb.Text = "select code_course,count(*) AS num FROM style_test WHERE code_course='1' group by code_course";
ds.Relations.Add("myrelation",
ds.Tables["course"].Columns["id_course"],
ds.Tables["course1"].Columns["id_course"]);
ds.Relations.Add("myrelation1",
ds.Tables["course1"].Columns["code_course"],
ds.Tables["course2"].Columns["code_course"]);
parentRepeater.DataSource = ds.Tables["course"];
Page.DataBind();
cnn.Close();
}
else
{
Response.Write("<script type=\"text/javascript\">" + "alert('คุณยังไม่มีรายวิชา<br>กรุณาเพิ่มรายวิชา');" +
"window.location = 'Create_course.aspx?id_teacher=" + Session["id_teacher"] + "';" + "</" + "script>");
}
}
void Page_UnLoad()
{
objConn.Close();
objConn = null;
}
void add_course(Object sender, EventArgs e)
{
Session["term"] = this.lblTerm.Text;
Session["term_year"] = this.lblTerm_year.Text;
Response.Redirect("Create_course1.aspx?id_teacher=" + Session["id_teacher"] + "&term=" + Session["term"] + "&term_year=" + Session["term_year"] + "");
}
protected void myRepeater_ItemDataBound(Object sender, RepeaterItemEventArgs e)
{
/*Label lblNum = (Label)(e.Item.FindControl("lblNum"));
if (lblNum != null)
{
lblNum.Text = (string)DataBinder.Eval(e.Item.DataItem, "[\"num\"]");
}*/
HyperLink hplEdit = (HyperLink)(e.Item.FindControl("hplEdit"));
if (hplEdit != null)
{
hplEdit.Text = "แก้ไข";
hplEdit.NavigateUrl = "Edit_course.aspx?code_course=" + DataBinder.Eval(e.Item.DataItem, "[\"code_course\"]") + "&id_course=" + DataBinder.Eval(e.Item.DataItem, "[\"id_course\"]") + "§ion=" + DataBinder.Eval(e.Item.DataItem, "[\"section\"]") + "&term=" + DataBinder.Eval(e.Item.DataItem, "[\"term\"]") + "&term_year=" + DataBinder.Eval(e.Item.DataItem, "[\"term_year\"]");
}
HyperLink hplExam = (HyperLink)(e.Item.FindControl("hplExam"));
if (hplExam != null)
{
hplExam.Text = "จัดการสอบ";
hplExam.NavigateUrl = "WebForm1.aspx?id_course=" + DataBinder.Eval(e.Item.DataItem, "[\"id_course\"]") + "§ion=" + DataBinder.Eval(e.Item.DataItem, "[\"section\"]") + "&term=" + DataBinder.Eval(e.Item.DataItem, "[\"term\"]") + "&term_year=" + DataBinder.Eval(e.Item.DataItem, "[\"term_year\"]");
}
}
void Back_course(Object sender, EventArgs e)
{
string id_teacher = Session["id_teacher"].ToString();
Session["id_teacher"] = id_teacher;
Session["term"] = this.lblTerm.Text;
Session["term_year"] = this.lblTerm_year.Text;
Response.Redirect("Back_course.aspx");
}
void Edit(Object sender, EventArgs e)
{
Response.Redirect("WebForm1.aspx?id_course=");
}
</script>
<html>
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<center>
<asp:Label ID="lblDetial" runat="server" Text="รายวิชา" Font-Size="Larger" Font-Bold="true" />
<br />
<asp:Button ID="Button1" runat="server" Text="Back" OnClick = "Back_course" />
ภาคเรียนที่ <asp:Label ID="lblTerm" runat="server" /> / <asp:Label ID="lblTerm_year" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Next" />
</center><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd /><dd />
<asp:Button ID="btAdd_course" Text="เพิ่มรายวิชา" runat="server" OnClick="add_course"/> <br />
<asp:repeater id="parentRepeater" runat="server">
<HeaderTemplate><table border="1" align="center" width="30%"></HeaderTemplate>
<itemtemplate>
<tr><td>
<b>รหัสวิชา <asp:Label ID="lblID_course" runat="server" ><%# DataBinder.Eval(Container.DataItem,"id_course") %></asp:Label>
วิชา <%# DataBinder.Eval(Container.DataItem,"name_course") %>
</b><br>
<asp:repeater id="childRepeater" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' OnItemDataBound="myRepeater_ItemDataBound" runat="server">
<itemtemplate>
<dd /> Section. <%# DataBinder.Eval(Container.DataItem, "[\"section\"]")%>
<asp:repeater id="childRepeater1" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("myrelation1") %>' runat="server">
<itemtemplate>
สอบทั้งหมด <%# DataBinder.Eval(Container.DataItem, "id_st")%> ครั้ง
</itemtemplate>
</asp:repeater>
<asp:HyperLink ID="hplEdit" runat="server" />
<asp:HyperLink ID="hplExam" runat="server" />
<br>
</itemtemplate>
</asp:repeater>
<br />
</td></tr>
</itemtemplate>
</asp:repeater>
<asp:Label ID="lb" runat="server" />
</form>
</body>
</html>
พอรันโค้ดด้านบนแล้วมัน error แบบนี้ครับ...ช่วยดูให้หน่อยนะครับ
Tag : ASP.NET, Ms SQL Server 2005, Web (ASP.NET), C#
|
|
|
|
|
|
Date :
2012-03-20 17:07:08 |
By :
gigclubbeer |
View :
1044 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
น่าจะติดตรงเรียก DataSource ครับ
|
|
|
|
|
Date :
2012-03-21 17:50:17 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|