我想从oracle数据库中获取多个数据,并希望将其存储到C#.net中的另一个变量中。
我正在使用此代码。
public static void FetchData(string MeterSerialNumber, string MeterManufacturer, string MeterType, XmlDocument xmlReXML, string StartTime, string StopTime)
{
string Acctid = "";
string Ser = "";
string name1 = "";
string towns = "";
string Qry = "SELECT DISTINCT AC.ACCOUNTID as accid ,MT.SERIALNUMBER as srno,AC.NAME as names,OC.OPCONAME as town1,OC.CITY discm FROM ACCOUNT AC, XXMETERHIST M, LSMDPHYSICALMETER MT,LSSERVICEPOINT P,LSMDMTRMANUFACTURER MANUFAC,OPERATINGCOMPANY OC,LSMARKET LS WHERE AC.UIDACCOUNT = M.UIDACCOUNT AND M.UIDPHYSICALMETER = MT.UIDPHYSICALMETER and LS.MARKETID = OC.OPCOCODE and LS.UIDMARKET = P.UIDMARKET and MANUFAC.UIDMTRMANUFACTURER = MT.UIDMETERMANUFACTURER AND M.UIDSERVICEPOINT = P.UIDSERVICEPOINT and MT.SERIALNUMBER ='?' AND MT.UIDPHYSMTRTYPE = '43'";
OleDbConnection con = new OleDbConnection("provider=MSDAORA.oracle;user id=testapp;password=testapp;data source=mdmdb_tb");
DataTable dtbl = new DataTable();
OleDbDataAdapter dad = new OleDbDataAdapter(Qry, con);
dad.SelectCommand.Parameters.Add("?", OleDbType.VarChar).Value = MeterSerialNumber;
con.Open();
dtbl.Columns.Add("accid");
dtbl.Columns.Add("srno");
dtbl.Columns.Add("names");
dtbl.Columns.Add("town1");
dtbl.Columns.Add("discm");
dad.Fill(dtbl);
if (dtbl.Rows.Count > 0)
{
Acctid = (dtbl.Rows[0].ItemArray[0].ToString());
Ser = (dtbl.Rows[0].ItemArray[1].ToString());
name1 = (dtbl.Rows[0].ItemArray[2].ToString());
towns = (dtbl.Rows[0].ItemArray[3].ToString());
}
}
但是数据并没有保存在所有变量中。它抛出了boundout的boundout异常。
答案 0 :(得分:1)
不确定这是问题的根源,但这可能会从SQL查询中提供一些奇怪的数据:
您的意思是OC.CITY AS discm
而不是OC.CITY discm
吗?
另外,只是建议您可能要为数据表的列指定类型:
dtbl.Columns.Add("accid", typeof(int));
dtbl.Columns.Add("srno", typeof(int));
dtbl.Columns.Add("names", typeof(string));
等