现在我要从这个表中,根据formularid(公式编号),选择相应的公式,如formularid=9,,然后选择formularindex=1时候,从tablename=labellist查询出columname=createdate下的所有值,,然后再查询formularindex=2的tablename=labellist查询出columname=id下的所有值,,接着再查询formularindex=3的tablename=labellist查询出columname=type下的所有值,,,接着再查询formularindex=4的tablename=Partslabel查询出columname=id下的所有值....直到formlarid=9的formularindex为最大值5时查询结束,,,
然后把以上查询得到的各个columname下的值得依次串起来,打印出来,,,
比如我要得到string str1="formularindex=1时候,从tablename=labellist查询出columname=createdate下的第一个值"+"formularindex=2的tablename=labellist查询出columname=id下的第一个值"+...+"formularindex=4的tablename=Partslabel查询出columname=id下的第一个值"+...然后再得到str2="...的第一个值"+"...第二个值"+...+"...第二个值"+...
...
str3="...的第二个值"+ "..的第一个值"+...+...这个怎么做呢?高手帮忙啊?以下是我写的方法的一部分代码,写到这里继续不下去了,,思维很乱,一直都想不通了,,请大家帮忙,谢谢啦!!
项目进行到这里,最关键的地方了,
public void GetPrintExpress()
{
string formularId=GetFormularId();
string sqlcmd = "select count(*) from BarPrint.dbo.BarFormularEntry where formularId=" + formularId;
int count = int.Parse(op.ExcSqlCmdReturn(sqlcmd, "BarFormularEntry"));
for (int i = 1; i <= count; i++)
{
string sql = "select tableName,columnName from BarPrint.dbo.BarFormularEntry where formularIndex=" + i;
DataSet ds = op.SelectInfo(sql, "BarFormularEntry");
string tableName = ds.Tables[0].Rows[0][0].ToString();
string columnName = ds.Tables[0].Rows[0][1].ToString();
string sqlcmd2 = "select " + columnName + " from " + tableName;
DataSet ds2 = op.SelectInfo(sqlcmd2, "columnNameTable");
string sqlCount = "select count(*) from " + tableName;
int countc = int.Parse(op.ExcSqlCmdReturn(sqlCount, "numTable"));
string[] columnValues;
for (int j = 0; j < countc; j++)
{
columnValues = new string[j];
columnValues[j] = ds2.Tables[0].Rows[j][0].ToString();
}
StringBuilder sb = new StringBuilder();
...
... }
}
然后把以上查询得到的各个columname下的值得依次串起来,打印出来,,,
比如我要得到string str1="formularindex=1时候,从tablename=labellist查询出columname=createdate下的第一个值"+"formularindex=2的tablename=labellist查询出columname=id下的第一个值"+...+"formularindex=4的tablename=Partslabel查询出columname=id下的第一个值"+...然后再得到str2="...的第一个值"+"...第二个值"+...+"...第二个值"+...
...
str3="...的第二个值"+ "..的第一个值"+...+...这个怎么做呢?高手帮忙啊?以下是我写的方法的一部分代码,写到这里继续不下去了,,思维很乱,一直都想不通了,,请大家帮忙,谢谢啦!!
项目进行到这里,最关键的地方了,
public void GetPrintExpress()
{
string formularId=GetFormularId();
string sqlcmd = "select count(*) from BarPrint.dbo.BarFormularEntry where formularId=" + formularId;
int count = int.Parse(op.ExcSqlCmdReturn(sqlcmd, "BarFormularEntry"));
for (int i = 1; i <= count; i++)
{
string sql = "select tableName,columnName from BarPrint.dbo.BarFormularEntry where formularIndex=" + i;
DataSet ds = op.SelectInfo(sql, "BarFormularEntry");
string tableName = ds.Tables[0].Rows[0][0].ToString();
string columnName = ds.Tables[0].Rows[0][1].ToString();
string sqlcmd2 = "select " + columnName + " from " + tableName;
DataSet ds2 = op.SelectInfo(sqlcmd2, "columnNameTable");
string sqlCount = "select count(*) from " + tableName;
int countc = int.Parse(op.ExcSqlCmdReturn(sqlCount, "numTable"));
string[] columnValues;
for (int j = 0; j < countc; j++)
{
columnValues = new string[j];
columnValues[j] = ds2.Tables[0].Rows[j][0].ToString();
}
StringBuilder sb = new StringBuilder();
...
... }
}
解决方案 »
- 关于C#调用XMLRPC库后客户端无法解析服务器返回的中文的问题
- 刷新会执行上一步操作
- 使用LINQ TO SQL删除时出现了这样的错误
- c#如何截取某网页内容
- 水晶报表插入图片的问题
- 关于listview的问题,比较棘手,谢谢
- 急!!!我在运行C#色时候总遇到同一个错误 请各位大哥帮帮忙!!!!
- 可以固定某一列,即当滚动条滚动的时候被固定的列不随之滚动,请问这个效果怎么做?
- 很菜的问题:请高手进来看看.
- 请把你的手给我!解决马上结贴。
- 关于DevExpress 的 DockManager
- 有谁用过sqlWhereBuilder服务器控件的field dropdown绑定过数据库字段吗?如何实现的....只有这么多分了.
对不起啊,分数设置太少了!
string sql="select index,tablename,columnname from 表名 where id="+fid;
//这里某些字段我简化了,换成你实际应用的拼写即可。表名没仔细看,用汉字代替了。 sqlcommand comm=new sqlcommand(sql,conn); sqldatareader dr=comm.executereader();
struct names
{ string tablename;
string columnname;
public names(string s1,string s2)
{ tablename=s1;
columnname=s2;
}
}
list<names> lis=new list<names>();
while(dr.read())
{ names n=new names(dr["tablename"].tostring(),dr["columnname"].tostring());
lis.add(n);
}
dr.dispose();
comm.dispose();
conn.close();
string s=null;
foreach(names n in lis)
{ string s="select n.columnname from"+n.tablename;//没理解错的话,好像楼主没提到有where条件
sqlcommand comm2=new sqlcommand(s,conn);
conn.open();
sqldatareader dr=comm.executereader();
while(dr.read())
{ s+=dr[""].tostring();
}
dr.dispose();
comm2.dispose();
conn.close();
}