讀取Web.config中設定
Conn = new SqlConnection(ConfigurationSettings.AppSettings[“cnFriends.ConnectString”]);
<appSettings> <!-- User application and configured property settings go here.--> <!-- Example: <add key="settingName" value="settingValue"/> --> <add key="cnFriends.ConnectionString" value="data source=(local)\NetSdk;initial catalog=FriendsData;user id=sa" /> </appSettings>
幾個命名空間
#當使用DataSet時,用using system.Data.SqlClient
#當設定Web.config時,用using system.Configuration
這個讓我想起了大一學習C語言時
bool visible btnSearch.Text = visible? “New Search” : “Search” ;
這個也蠻好
dsResult.tables[“Users”].rows.count Conver.Tonint32(ConfigurationSettings.AppSettings[“Cokuale.number”]);
夠狠1:用Session儲存結果並綁定
Session[“Search”] = dsResults; dsResults = (DataSet) Session[“Search”];
grdResults.DataBind();
其實,Session,Application等存的是object 類型,因此,最後都要顯式轉換型別
順便說說,判斷是否取到字串型別的值用null 判斷。
夠狠2:從DataTable中選擇行
DataRow[] rows = dsResults.Tables[“Users”].Select(filter); dsResults = dsResults.Clone(); foreach(DataRow row in rows) { dsResults.Tables[“Tables”].ImportRow(row); }
取得webForm 上的一個控制項
ImageButton img = (ImageButton)e.Item.FindControl(“Selectbutton”)
跳轉:
##
Server.Transfer(“Caoxicao.aspx”);
imgShow.Attributes.Add(“onclick”,”document.getElementById(‘tbPrefs').style.display = ‘block';”);
img.Style.Add(“Cursor”,'Pointer');
ColorConvert cv = new ColorConvert(); Color selected = Color.Empty; Selected = (olor)cv.ConvertFromString(White);
Response.Cookies.Add(new HttpCookie(“backColor”,r))
Using FriendsReunion.Controls; Protectd override void Oninit(EventArgs e) { FriendsFooter _footer = (FriendsFooter)LoadControl(Request.ApplicationPath+”/Controls/ FriendsFooter.aspx”); SubHeader _subHeader = new SubHeader(); } Page.Contros.AddAt(0,_footer); Page.Contros.AddAt(0,_subHeader); base.OnInit(e); }
HtmlGenericControl p = new HtmlGenericControl(“p”); p.Style.Add(“background-color”,bg);
、
和 ######返回DataSet ##### #Public DataSet Contact() { String sql = “@ Select * from … …”; DataSet requests = new DataSet(); New SqlDtaAdapter (sql,conn).Fill(requests); //return requests.GetXml(); Return requests; }
DataSet results = new DataSet(); Results.ReadXml(new StringReader(fi.ContactRequest(userid)));
FriendsService.FriendsInfo fi = new FriendsService.FriendsInfo(); String userid; Userid = fi.GetUserID(“…”);
HyperLink reg = new HyperLink(); Reg.ToolTip = “… …”;
System.Web.Security.Forms.Authentication.SignOut(); Response.write (Request.ApplicaltionPath);
Trace.Write Trace.Warn
Try { … … } Catch(ArgumentNullExeption e) { … }
<Custom Errors mode = “on” defaultRedriect = “customerror.aspx”; />
以上是C#Web應用程式入門經典筆記(下冊)的詳細內容。更多資訊請關注PHP中文網其他相關文章!