大区省市问题. 如果我在数据库里要查一个大区,省市,城市我需要进行判断.从小的城市判断,如果没有城市 则添加城市,如果没有大区则添加大区.以此类推.完整的代码 给个解释. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 LZ 老是回答你的问题.//当大区下面有省市,省市没有城市的时候 if (!string.IsNullOrEmpty(this.txtRegion.Text) && !string.IsNullOrEmpty(this.txtProvince.Text) && string.IsNullOrEmpty(this.txtCity.Text)) { SqlCommand SqlCmd = new SqlCommand(); //SQL语句则添加进去此省市 SqlCmd.CommandText = "INSERT INTO BaseGeography " + " (Name_EN,ParentID) " + " VALUES " + " ('Name_EN','Name_EN')"; AddCity(); } //当三个东西都有的时候 if (!string.IsNullOrEmpty(this.txtRegion.Text) && !string.IsNullOrEmpty(this.txtProvince.Text) && !string.IsNullOrEmpty(this.txtCity.Text)) { SqlCommand SqlCmd = new SqlCommand(); //都有的时候则给其提示说此东西都有 SqlCmd.CommandText = "INSERT INTO BaseGeography " + " (Name_EN,CitySN,ParentID) " + " VALUES " + " ('Name_EN','CitySN','Name_EN')"; AddCity(); } }SqlCmd.CommandText = "SELECT COUNT(*) FROM ( SELECT Regoin.Name_CN AS Regoin," + " Procince.Name_CN AS Procince ," + " City.Name_CN AS City " + " FROM " + " BaseGeography AS Regoin LEFT JOIN " + " BaseGeography AS Procince ON Regoin.CityID=Procince.ParentID LEFT JOIN " + " BaseGeography AS City ON City.ParentID=Procince.CityID) A" + " WHERE A.Regoin =' " + this.txtRegion.Text + "'" + " AND A.Procince ='" + this.txtProvince.Text + " '" + " AND A.City ='" + this.txtCity.Text + "'"; DataSet ds; if (AccessSqlCmd.Execute(out ds)) { ds.Tables["info"].Rows[0][0].ToString(); } //如果大区的文本框里面不为空. if (string.IsNullOrEmpty(this.txtRegion.Text) && string.IsNullOrEmpty(this.txtProvince.Text) && string.IsNullOrEmpty(this.txtCity.Text)) { //判断大区的txtBox有没有值 if (this.txtRegion.Text == null) { Response.Write("大区不能为空"); SqlCmd.CommandText = "SELECT * FROM BaseGeography WHERE LevelID=0 OR ParentID=CityID"; //对比数据库大区的值 //如果有,则Eorr ! //else 则 INSERT } } AddCity();参考一下吧 . 看 楼主的思路 蛮清晰的嘛。 哪里 有问题,代码 还是 sql语句有问题? 用dsoframer.ocx将word文档内嵌在winform中,怎么获取word文档里面的值 请问在网页设计中怎么控制其他页面中的控件? SQL 查询问题 2005中DataGridview如何綁定數據? 如何让客户端按下“文件更新”按钮后,从服务器上Copy指定目录下的所有文件覆盖客户机上指定目录下的文件(不需要版本比较,覆盖就可了) 在线等啊,谁知道这个是什么错误不哟?? 怎么打开C# Compiler? 关于图片上传问题 HttpWebRequest取到乱码 请问哪里可以找到关于Duwamish7的详细文档,或者参考资料? 关于winfrom布局的问题 求解vs2008的问题
if (!string.IsNullOrEmpty(this.txtRegion.Text) && !string.IsNullOrEmpty(this.txtProvince.Text) && string.IsNullOrEmpty(this.txtCity.Text))
{
SqlCommand SqlCmd = new SqlCommand();
//SQL语句则添加进去此省市
SqlCmd.CommandText = "INSERT INTO BaseGeography " +
" (Name_EN,ParentID) " +
" VALUES " +
" ('Name_EN','Name_EN')"; AddCity();
}
//当三个东西都有的时候
if (!string.IsNullOrEmpty(this.txtRegion.Text) && !string.IsNullOrEmpty(this.txtProvince.Text) && !string.IsNullOrEmpty(this.txtCity.Text))
{
SqlCommand SqlCmd = new SqlCommand();
//都有的时候则给其提示说此东西都有
SqlCmd.CommandText = "INSERT INTO BaseGeography " +
" (Name_EN,CitySN,ParentID) " +
" VALUES " +
" ('Name_EN','CitySN','Name_EN')";
AddCity();
}
}
SqlCmd.CommandText = "SELECT COUNT(*) FROM ( SELECT Regoin.Name_CN AS Regoin," +
" Procince.Name_CN AS Procince ," +
" City.Name_CN AS City " +
" FROM " +
" BaseGeography AS Regoin LEFT JOIN " +
" BaseGeography AS Procince ON Regoin.CityID=Procince.ParentID LEFT JOIN " +
" BaseGeography AS City ON City.ParentID=Procince.CityID) A" +
" WHERE A.Regoin =' " + this.txtRegion.Text + "'" +
" AND A.Procince ='" + this.txtProvince.Text + " '" +
" AND A.City ='" + this.txtCity.Text + "'";
DataSet ds;
if (AccessSqlCmd.Execute(out ds))
{
ds.Tables["info"].Rows[0][0].ToString();
}
//如果大区的文本框里面不为空.
if (string.IsNullOrEmpty(this.txtRegion.Text) && string.IsNullOrEmpty(this.txtProvince.Text) && string.IsNullOrEmpty(this.txtCity.Text))
{
//判断大区的txtBox有没有值
if (this.txtRegion.Text == null)
{
Response.Write("大区不能为空");
SqlCmd.CommandText = "SELECT * FROM BaseGeography WHERE LevelID=0 OR ParentID=CityID";
//对比数据库大区的值
//如果有,则Eorr !
//else 则 INSERT
}
}
AddCity();
参考一下吧 .