我刚刚接触oracle 需要和.NET连接在一起
在.net里要同时提取表里的两个字段!根据用户名和日期提取上班时间和下班时间
table 叫xinxi 用户名 name 上班 下班分别为shangban xiaban 日期叫date
下面是我写的代码,数据库连接没有问题,上班没有问题,可以显示:但是下班不显示,可是也不报错:帮忙找一下错误吧:for(int i=0;i<ds.Tables["ss"].Rows.Count;i++)
{
    sqltxt="select shangban,xiaban from xinxi 
        where name="'"+users[i].Text+"' and date='"+lab_tadate.Text+"'";
    OracleCommand cmd=new OracleCommand(sqltext1,myConnection);
    OracleDataReader oc=cmd.ExecuteReader();
    if(oc.Read()&&odr.GetValue(0).ToString()!="")
    {
users[i].Text=users[i].Text+"\n    上班:"+oc.GetValue(0);
    }
    else if(odr.Read()&&odr.GetValue(0).ToString()!="")
    {
users[i].Text=users[i].Text+"\n 下班:"+oc.GetValue(1);
     }
     oc.Close();
     users[i].Enabled = true;
}

解决方案 »

  1.   

    for(int i=0;i<ds.Tables["ss"].Rows.Count;i++)
    {
        sqltxt="select shangban,xiaban from xinxi 
            where name="'"+users[i].Text+"' and date='"+lab_tadate.Text+"'";
        OracleCommand cmd=new OracleCommand(sqltext1,myConnection);
        OracleDataReader oc=cmd.ExecuteReader();
        if(oc.Read()&&odr.GetValue(0).ToString()!="")
        {
    users[i].Text=users[i].Text+"\n    上班:"+oc.GetValue(1);  --这里1
        }
        else if(odr.Read()&&odr.GetValue(0).ToString()!="")
        {
    users[i].Text=users[i].Text+"\n 下班:"+oc.GetValue(2);  --这里2
         }
         oc.Close();
         users[i].Enabled = true;
      

  2.   

    for(int i=0;i<ds.Tables["ss"].Rows.Count;i++)
    {
        sqltxt="select shangban,xiaban from xinxi 
            where name="'"+users[i].Text+"' and date='"+lab_tadate.Text+"'";
        OracleCommand cmd=new OracleCommand(sqltext1,myConnection);
        OracleDataReader oc=cmd.ExecuteReader();
        if(oc.Read()&&odr.GetValue(0).ToString()!="")
        {
    users[i].Text=users[i].Text+"\n    上班:"+oc.GetValue(0)+"\n 下班:"+oc.GetValue(1);
        }
        
         oc.Close();
         users[i].Enabled = true;
    }
      

  3.   

    还需要注意,数据库中得数据是不是null
      

  4.   

    是varchar型的 问题已经解决了
    但又有了新问题 长时间运行 会出现oracle03113错误
    我用的是Oracle - OraHome92   在客户端连接的服务器 怎么办啊