private void BtnInsertProvince_Click(object sender, EventArgs e) { int ret = 0; int count = 0; Access DBAccess = new Access(); DataSet dsProvince = new DataSet(); string strSqlProvince = string.Empty; string strSqlInsert = string.Empty; int intProvinceCount = 0; string strProvinceID = string.Empty; string strProvinceName = string.Empty; string strCityName = string.Empty; strSqlProvince = $"select ProvinceName from S_Province"; dsProvince = DBAccess.ReadSQLserver(strSqlProvince, "temp"); intProvinceCount = dsProvince.Tables[0].DefaultView.Count; for (int i = 0; i < intProvinceCount; i++) { strProvinceName = dsProvince.Tables[0].Rows[i][0].ToString(); strSqlInsert = $"insert into province(province) " + $"values('{strProvinceName}')"; ret = DBAccess.ReadMySQL(strSqlInsert); if (ret == 1) { count++; } DialogResult DRret; DRret = MessageBox.Show("已完成:" + strProvinceName + "的记录是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (DRret.Equals(DialogResult.No)) { break; } } }
private void BtnInsertChina_Click(object sender, EventArgs e) { int ret = 0; int count = 0; Access DBAccess = new Access(); DataSet dsProvince = new DataSet(); DataSet dsCity = new DataSet(); DataSet dsDistrict = new DataSet(); string strSqlProvince = string.Empty; string strSqlCity = string.Empty; string strSqlDistrict = string.Empty; string strSqlInsert = string.Empty; int intProvinceCount = 0; int intCityCount = 0; int intDistrictCount = 0; string strProvinceID = string.Empty; string strCityID = string.Empty; string strProvinceName = string.Empty; string strCityName = string.Empty; string strDistrictName = string.Empty; strSqlProvince = $"select ProvinceID,ProvinceName from S_Province"; dsProvince = DBAccess.ReadSQLserver(strSqlProvince, "temp"); intProvinceCount = dsProvince.Tables[0].DefaultView.Count; for (int i = 0; i < intProvinceCount; i++) { strProvinceID = dsProvince.Tables[0].Rows[i][0].ToString(); strSqlCity = $"select CityID,CityName from S_City where ProvinceID='{strProvinceID}'"; dsCity = DBAccess.ReadSQLserver(strSqlCity, "temp"); intCityCount = dsCity.Tables[0].DefaultView.Count; for (int j = 0; j < intCityCount; j++) { strCityID = dsCity.Tables[0].Rows[j][0].ToString(); strSqlDistrict = $"select DistrictName from S_District where CityID='{strCityID}'"; dsDistrict = DBAccess.ReadSQLserver(strSqlDistrict, "temp"); intDistrictCount = dsDistrict.Tables[0].DefaultView.Count; for (int k = 0; k < intDistrictCount; k++) { strProvinceName = dsProvince.Tables[0].Rows[i][1].ToString(); strCityName = dsCity.Tables[0].Rows[j][1].ToString(); strDistrictName = dsDistrict.Tables[0].Rows[k][0].ToString(); strSqlInsert = $"insert into china(number,province,city,district) " + $"values('{Convert.ToString(i)}','{strProvinceName}','{strCityName}','{strDistrictName}')"; ret = DBAccess.ReadMySQL(strSqlInsert); if (ret == 1) { count++; } } } DialogResult DRret; DRret = MessageBox.Show("已完成:" + strProvinceName + "的记录是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (DRret.Equals(DialogResult.No)) { break; } } MessageBox.Show(Convert.ToString(count), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }