以下語法其主要功能是去資料庫來產生網頁的下拉選單效果,而我是試著將原本SQL的版本改成postgresql的連線方式,但在執行後都會出現下列的訊息
編譯器錯誤訊息: CS1513: 必須是 }
原始程式錯誤:
行 825: }
行 826:
行 827: [System.Diagnostics.DebuggerNonUserCodeAttribute()]
行 828: protected override void FrameworkInitialize() {
行 829: base.FrameworkInitialize();
原始程式檔: c:\Users\kpm90_000\AppData\Local\Temp\Temporary ASP.NET Files\website\eb63fe47\900e4c65\App_Web_03_stackholder.aspx.56c48f6f.wbkrqdlp.0.cs 行: 827
而我目前的語法如下,有無前輩有類似的經驗可提供解答問題的方向呢?感謝
<%
//上方欄位的下拉選單的功能---------start
String[] tTitleAr = new string[3]{DBaboutcaty,DBenvirnduty,DBcareer};
String[] tSqkAr = new string[3]{" and xlv='1' ","",""};
String[] tshowAr = new string[5];
for(tzenki=0;tzenki<tTitleAr.Length;tzenki++){
String show_str;
show_str="<div id='show_"+tzenki+"' class='show_menu_div'><div class='show_menu_ul' id='show_menu_ulshow_"+tzenki+"' >";
NpgsqlConnection conn3 =
new NpgsqlConnection("Server=10.10.10.208;Port=5432;User Id=confluence;Password=confluence;Database=DB17;");
conn3.Open();
NpgsqlCommand command3 =
new NpgsqlCommand("select * from " + tTitleAr[tzenki] + " where xpublish='yes' " + tSqkAr[tzenki] + " order by xorder asc", conn3);
try
{
NpgsqlDataReader reader3 = command3.ExecuteReader();
while (reader3.Read())
{
switch (tzenki){
case 0:
xlink_pre=WebPath+"01_about/";
if(reader3["xwhere"].ToString()=="Link"){
xlink_pre+=reader3["xlink"].ToString();
}else{
xlink_pre+="01_about.aspx";
}
xlink_pre+="?aid="+reader3["pid"].ToString();
break;
case 1:
if(reader3["xwhere"].ToString()=="SmartEditor")
xlink_pre=WebPath+"02_envirn/01_labor.aspx?eid="+reader3["pid"].ToString();
else
xlink_pre=WebPath+"02_envirn/05_download.aspx?eid="+reader3["pid"].ToString();
break;
case 2:
xlink_pre=WebPath+"03_career/";
if(reader3["xwhere"].ToString()=="Link"){
xlink_pre+=reader3["xlink"].ToString();
}else{
xlink_pre+="01_benefits.aspx";
}
xlink_pre+="?cid="+reader3["pid"].ToString();
break;
default:
xlink_pre=tzenki.ToString();
break;
}
show_str+="<li class='show_menu_li'><a href='"+xlink_pre+"'>"+reader3["xtitle"].ToString()+"</a></li>";
}
show_str+="</div></div>";
tshowAr[tzenki]=show_str;
}
finally
{
conn3.Close();
}
tshowAr[3]="<div id='show_3' class='show_menu_div'><div class='show_menu_ul' id='show_menu_ulshow_3' ><li class='show_menu_li'><a href='"+WebPath+"01_about/01_about.aspx?aid=3'>資訊1</a></li><li class='show_menu_li'><a href='"+WebPath+"04_ir/05_manage_a01.aspx'>資訊2</a></li><li class='show_menu_li'><a href='"+WebPath+"04_ir/01_irs.aspx'>資訊4</a></li><li class='show_menu_li'><a href='"+WebPath+"04_ir/rnings.aspx'>資訊3</a></li><li class='show_menu_li'><a href='"+WebPath+"04_ir/03_sharehol.aspx'>資訊5</a></li><li class='show_menu_li'><a href='"+WebPath+"04_ir/04_ircontact.aspx'>資訊6</a></li></div></div>";
tshowAr[4] = "<div id='show_4' class='show_menu_div'><div class='show_menu_ul' id='show_menu_ulshow_4' ><li class='show_menu_li'><a href='" + WebPath + "05_contact/03holder.aspx'>資訊8</a></li><li class='show_menu_li'><a href='" + WebPath + "05_contact/01_contact.aspx'>資訊7</a></li><li class='show_menu_li'><a href='" + WebPath + "05_contact/02_contact.aspx'>資訊9</a></li></div></div>";
%>
SQL指令與輸入字串的組合.....記得使用 "參數"寫法,避免SQL Injection
http://mis2000lab.pixnet.net/blog/post/34581695
***DataReader (SqlCommand)***
String SQLString = "Select * From test Where id = @id "; // 注意到沒? 連「單引號」都不可以出現
SqlCommand cmd = new SqlCommand(SQLString, Conn);
cmd.Parameters.Add("@id", SqlDbType.Int, 4);
cmd.Parameters["@id"].Value =TextBox1.Text;
//簡易寫法。 cmd.Parameters.AddWithValue("@參數名稱", 輸入的數值);
//上面兩段參數,可以寫成 cmd.Parameters.AddWithValue("@id", TextBox1.Text);