从数据类型varchar转换为float时出错,出去''后又出现c#列名无效d的问题
var river = comboBox1.SelectedItem.ToString();
var begin = comboBox2.SelectedItem.ToString();
var end = comboBox3.SelectedItem.ToString();
var datasource = new DataSet();
if (begin == "全部" && end == "全部")
{
datasource = new DALBase().WorkToSql("select * from 污染物 where 断面名称='" + river + "'");
}
else if (begin != "全部" && end == "全部")
{
datasource = new DALBase().WorkToSql("select * from 污染物 where 断面名称='" + river + "'and 采样年度='" + begin + "'");
}
else
{
datasource = new DALBase().WorkToSql("select * from 污染物 where 断面名称='" + river + "' and 采样年度='" + begin + "' and 采样月='" + end + "'");
}
dataGridView1.DataSource = datasource.Tables[0];
}
private void 伊通河各短命主要污染物1_Load(object sender, EventArgs e)
{
FileCombox1();
}
private void FileCombox1()
{
var result = new DALBase().WorkToSql("select [断面名称] from 污染物 group by [断面名称]");
var datasoucre = new List<string>();
for (int i = 0; i < result.Tables[0].Rows.Count; i++)
{
datasoucre.Add(result.Tables[0].Rows[i]["断面名称"].ToString());
}
comboBox1.DataSource = datasoucre;
}
private void FileCombox2(string 断面名称)
{
var result = new DALBase().WorkToSql("select 采样年度 from 污染物 where 断面名称='" + 断面名称 + "' group by 采样年度 ");
var datasoucre = new List<string>();
datasoucre.Add("全部");
for (int i = 0; i < result.Tables[0].Rows.Count; i++)
{
datasoucre.Add(result.Tables[0].Rows[i]["采样年度"].ToString());
}
comboBox2.DataSource = datasoucre;
}
private void FileCombox3(string 断面名称, string 采样年度)
{
var result = new DALBase().WorkToSql("select 采样月 from 污染物 where 断面名称='" + 断面名称 + " 'and 采样年度='" + 采样年度 + "' group by 采样月 ");
var datasoucre = new List<string>();
datasoucre.Add("全部");
for (int i = 0; i < result.Tables[0].Rows.Count; i++)
{
datasoucre.Add(result.Tables[0].Rows[i]["采样月"].ToString());
}
comboBox3.DataSource = datasoucre;
}