C#执行数据库语句后结果是空的,但是把语句放在oracle中执行却有记录,咋回事?代码如下
publicclassclsOracle{protectedstaticstringconnectionString;publicclsOracle()//构造方法,保存...
public class clsOracle
{
protected static string connectionString;
public clsOracle()//构造方法,保存连接信息
{
connectionString = ConfigurationSettings.AppSettings["oraconn"].ToString();
}
public DataSet OraDataset(string strSql)//执行数据库语句
{
using (OracleConnection connection = new OracleConnection(connectionString))
{
using (OracleCommand cmd = new OracleCommand(strSql, connection))
{
try
{
DataSet ds = new DataSet();
OracleDataAdapter oda = new OracleDataAdapter();
oda.SelectCommand = cmd;
oda.Fill(ds);
connection.Close();
return ds;
}
catch (System.Data.OracleClient.OracleException E)
{
connection.Close();
throw new Exception(E.Message);
}
}
}
}
}
private void button9_Click(object sender, EventArgs e)//这个是按钮,点击触发事件
{
ReadGo2();
}
private void ReadGo2()
{
string strSql = "select * from tb_job";
clsOracle clsor = new clsOracle();
dataGridView5.DataSource = clsor.OraDataset(strSql).Tables[0];
} 展开
{
protected static string connectionString;
public clsOracle()//构造方法,保存连接信息
{
connectionString = ConfigurationSettings.AppSettings["oraconn"].ToString();
}
public DataSet OraDataset(string strSql)//执行数据库语句
{
using (OracleConnection connection = new OracleConnection(connectionString))
{
using (OracleCommand cmd = new OracleCommand(strSql, connection))
{
try
{
DataSet ds = new DataSet();
OracleDataAdapter oda = new OracleDataAdapter();
oda.SelectCommand = cmd;
oda.Fill(ds);
connection.Close();
return ds;
}
catch (System.Data.OracleClient.OracleException E)
{
connection.Close();
throw new Exception(E.Message);
}
}
}
}
}
private void button9_Click(object sender, EventArgs e)//这个是按钮,点击触发事件
{
ReadGo2();
}
private void ReadGo2()
{
string strSql = "select * from tb_job";
clsOracle clsor = new clsOracle();
dataGridView5.DataSource = clsor.OraDataset(strSql).Tables[0];
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询