作者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)
1F:→ Abbee:你cmdT没有加parameter 02/06 19:49
2F:→ te426odin:上下两个都是同一个方法,可是第一个是跑得出来的 02/06 19:55
3F:→ te426odin:第二个或者第三个就都跑不出来了 02/06 19:55
4F:→ te426odin:感谢Abbee前辈,我发现我的错误在哪边了,原来是 02/06 19:56
5F:→ te426odin:cmdT.parameter 才对 02/06 19:57
※ 编辑: te426odin 来自: 60.249.132.65 (02/06 20:06)
6F:→ emn178:cmd cmdT 02/08 09:13
7F:→ ssccg:一样的程式复制贴上很容易少改到变数名字 02/08 16:03