作者te426odin (小胖老師)
看板C_Sharp
標題[問題] 呼叫副程式的錯誤(已解決)
時間Wed Feb 6 19:46:10 2013
各位版大前輩大家好
我寫了一隻web副程式
是要動態控制下拉式選單的資料來源
副程式的部分
public void BindDropDownListData(string L1,string L2,string L3)
{
資料庫連結部分省略
conn.Open();
SqlCommand cmd = new SqlCommand("select pro_name,type_id From
Reg_Pro_Item where type_id=@typeid", conn);
cmd.Parameters.Add("typeid", SqlDbType.Char, 2).Value = L1;
SqlDataAdapter mySqlDataAdapter03 = new SqlDataAdapter(cmd);
DataSet myDataSet03 = new DataSet();
mySqlDataAdapter03.Fill(myDataSet03);
DDLpro1.DataSource = myDataSet03;
DDLpro1.DataTextField = "pro_name";
DDLpro1.DataValueField = "type_id";
DDLpro1.DataBind();
SqlCommand cmdT = new SqlCommand("select pro_name,type_id From Reg_Pro_Item
where type_id=@typeid", conn);
cmd.Parameters.Add("typeid", SqlDbType.Char, 2).Value = L2;
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(cmdT);
DataSet myDataSet = new DataSet();
mySqlDataAdapter.Fill(myDataSet); ←此段出現問題
DDLpro1.DataSource = myDataSet;
DDLpro1.DataTextField = "pro_name";
DDLpro1.DataValueField = "type_id";
DDLpro1.DataBind();
在第二個cmd的時候倒數第五行都會出現[必須宣告純量變數 "@typeid"]
試了好久都找不到問題,於是來此借助前輩們的幫忙
感激不盡
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.249.132.65
※ 編輯: te426odin 來自: 60.249.132.65 (02/06 19:47)
→ Abbee:你cmdT沒有加parameter 02/06 19:49
→ te426odin:上下兩個都是同一個方法,可是第一個是跑得出來的 02/06 19:55
→ te426odin:第二個或者第三個就都跑不出來了 02/06 19:55
→ te426odin:感謝Abbee前輩,我發現我的錯誤在哪邊了,原來是 02/06 19:56
→ te426odin:cmdT.parameter 才對 02/06 19:57
※ 編輯: te426odin 來自: 60.249.132.65 (02/06 20:06)
→ emn178:cmd cmdT 02/08 09:13
→ ssccg:一樣的程式複製貼上很容易少改到變數名字 02/08 16:03