简体   繁体   English

我想从oracle数据库中获取多个数据,并将其存储到C#.net中的另一个变量中

[英]I want to fetch multiple data from oracle database and want to store it into another variables in C# .net

I want to fetch multiple data from oracle database and want to store it into another variables in C# .net. 我想从oracle数据库中获取多个数据,并将其存储到C#.net中的另一个变量中。

I am using this code. 我正在使用此代码。

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());

      }
    }

But the data is not saved in all the variables.Its throwing Indexout of boundrange exception. 但是数据并没有保存在所有变量中,它会抛出Indexout超出边界范围异常。

Not sure that this would be the root of the issue, but this might be giving you some weird data from your SQL query: 不确定这是否是问题的根源,但这可能会给您一些来自SQL查询的奇怪数据:

Did you mean OC.CITY AS discm instead of OC.CITY discm ? 您是说OC.CITY AS discm而不是OC.CITY discm吗?

Also, just a suggestions that you might want to specify a type for the columns of your datatable: 另外,您可能需要为数据表的列指定类型的建议:

dtbl.Columns.Add("accid", typeof(int));
dtbl.Columns.Add("srno", typeof(int));
dtbl.Columns.Add("names", typeof(string));

etc. 等等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET C# 我想从一个数据中获取 ID(1/多个),如果它与另一个表的 ID 很接近 - .NET C# I want to get the IDs (1/multiple) from a data if it much the ID of another table 我想使用C#Linq从XML提取子节点的数据 - I want to fetch the data of child node from XML using C# Linq 当我想从数据库中获取数据时,连接没有打开 - Connection is not opening when I want to fetch data from database 我想在asp.net和C#中使用WCF一次添加多个图像和其他数据 - I want to Add multiple images and other data at a time using WCF in asp.net and C# C# 将数据库设置为我想要的特定数据 - C# set database to specific data that I want insert data into database using javascript in asp.net C# 将数据插入数据库后,我想创建警告框 - insert data into database using javascript in asp.net C# After inserting the data into database,i want to create the alert box 我想从数据库中检索多个数据。 我正在使用C#和SQL Server - I want to retrieve multiple data from my data base. Im using C# and sql server 我想在C#中将1个数组移到另一个数组 - I want to move 1 array to another in C# 我想使用C#从ArrayList检索数据 - I want to retrieve data from an ArrayList using c# 我想将数据从Lua发送到C# - I want to send data from Lua to C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM