private void cmb省_SelectedIndexChanged(object sender, EventArgs e)
{
ProvinceItem item = (ProvinceItem)cmb省.SelectedItem;
int proId = item.Id;
cmb市.Items.Clear();//清空上一次的选择数据
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\SS.mdf;
Integrated Security=true;user instance=true"))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from city where proID=@proID";
cmd.Parameters.Add(new SqlParameter("proID", proId));
using (SqlDataReader dataReader = cmd.ExecuteReader())
{
while (dataReader.Read())
{
string cityName=dataReader.GetString(dataReader.GetOrdinal("cityName"));
cmb市.Items.Add(cityName);
}
}
}
}
}
这里我int proId = item.Id; proId用的小写的d,
cmd.CommandText = "select * from city where proID=@proID";这里最后这个@proID我改成proId以后,运行的结果和原来一样的,
@XXX我知道是表示此处用参数代替的意思,是向Parameters中添加参数,
可是我想知道这里这个到底是怎么个情况,这里到底代表的是什么,哪个参数用来代替@XXX的,
本人比较菜,问题或许说的还不是很明了,请各位大神谅解, |