我如何... Dropdownlist过滤器在ASP.net中使用层架构 [英] How do I...Dropdownlist filter use layer architecture in ASP.net

查看:81
本文介绍了我如何... Dropdownlist过滤器在ASP.net中使用层架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

国家/地区aCountry = 国家/地区(); 
int countryId = aCountry.CountryId;
string quary = SELECT StateId,StateName FROM tCountryState WHERE countryId =' + countryId + ';
SqlConnection con = new SqlConnection(连接);
con.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(quary,con);
da.Fill(ds);
con.Close();
return ds;





[我的字符串问题在哪里? ????????????????????????????????????????????????????????????????????????????????????????????????? b $ b

国家/地区aCountry = 国家/地区(); 
int countryId = aCountry.CountryId;





aCountry new Country(); ,你怎么会得到 aCountry.CountryId ,它可能会返回null。



你的第二个错误是:

  string  quary =   SELECT StateId,StateName FROM tCountryState WHERE countryId =' + countryId +  '; 



here countryId int ,您也没有将其转换为 string 。你应该写成:

  string  quary =   SELECT StateId,StateName FROM tCountryState WHERE countryId =' + Convert.ToString(countryId)+  '; 


从此示例中获取提示: http://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx [ ^

Country aCountry=new Country();
            int countryId = aCountry.CountryId;
            string quary = "SELECT StateId,StateName FROM tCountryState WHERE countryId='"+countryId+"'";
            SqlConnection con = new SqlConnection(connection);
            con.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(quary, con);
            da.Fill(ds);
            con.Close();
            return ds;



[Where my string problem?????????????]

解决方案

Hi,
Here is your code:

Country aCountry=new Country();
int countryId = aCountry.CountryId;



While aCountry is new Country();, how would you get aCountry.CountryId, it might be returning null.

Your second mistake is :

string quary = "SELECT StateId,StateName FROM tCountryState WHERE countryId='"+countryId+"'";


here countryId is int and you are also not converting it to string. you should write as :

string quary = "SELECT StateId,StateName FROM tCountryState WHERE countryId='"+Convert.ToString(countryId)+"'";


Take cue from this example: http://www.aspsnippets.com/Articles/Creating-Cascading-DropDownLists-in-ASP.Net.aspx[^]


这篇关于我如何... Dropdownlist过滤器在ASP.net中使用层架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆