日期:2014-05-17 浏览次数:20938 次
StringBuilder sql2 = new StringBuilder();
sql2.Append("SELECT info.*,fkid");
DataSet lin = SqliteHelper.getDataset(sqlconn.conn, CommandType.Text, "select * from monthset", null);
DataTable dt = lin.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
sql2.Append(",[L" + dt.Rows[i]["monthname"].ToString() + "]");
sql2.Append(",[J" + dt.Rows[i]["monthname"].ToString() + "]");
}
sql2.Append("FROM info left join (");
sql2.Append("select fkid,");
for (int i = 0; i < dt.Rows.Count; i++)
{
sql2.Append("max(case smonth when '" + dt.Rows[i]["monthname"].ToString() + "' then sbyl else 0 end) as [L" + dt.Rows[i]["monthname"].ToString() + "],");
sql2.Append("max(case smonth when '" + dt.Rows[i]["monthname"].ToString() + "' then sbenjia else 0 end) as [J" + dt.Rows[i]["monthname"].ToString() + "],");
}
sql2.Remove(sql2.Length - 1, 1);
sql2.Append(" from submonth group by fkid) as tb on id=tb.fkid ");
try
{
ds = SqliteHelper.getDataset(sqlconn.conn, CommandType.Text, sql2.ToString(), null);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "读取资料错误");
}
ds.Tables[0].NewRow();来添加行就会报错:无效的存储类型DBNULL;上午用的时候还是可以的完全没有问题。下午就再也不行了,通过查看DataTable的列,发现通过case when 转换的列的类型是这样的:DataType