我想使用 ODBC 连接从 asp.net C# 将多行数据插入到 Hive 表中

问题描述 投票:0回答:0

`我写了下面的代码,用于 5 列的多个数据插入,但我需要它用于 100 多列,超过 10 条数据和快速执行。

> `OdbcCommand cmd = new OdbcCommand();
> OdbcDataAdapter odbc = new OdbcDataAdapter();
> cmd = Conn.CreateCommand();
> List\<string\> ReadFile = File.ReadAllLines(@"D:\\uc_Data.txt").ToList();
> int i = 0;  
> using (Conn)
> {
> Conn.Open();
> string names = string.Empty;
> string names1 = string.Empty;
> int count = 0;
> foreach (string customer in ReadFile)
> {
> var firstValue = ReadFile\[i\].Split(new string\[\] { "," }, StringSplitOptions.None)\[0\];
> var firstValue1 = ReadFile\[i\].Split(new string\[\] { "," }, StringSplitOptions.None)\[1\];
> var firstValue2 = ReadFile\[i\].Split(new string\[\] { "," }, StringSplitOptions.None)\[2\];
> var firstValue3 = ReadFile\[i\].Split(new string\[\] { "," }, StringSplitOptions.None)\[3\];
> var firstValue4 = ReadFile\[i\].Split(new string\[\] { "," }, StringSplitOptions.None)\[4\];`
> 
> 
> if (count <= 250000)
> >                     {
> names += "(" + firstValue + "," + "'" + firstValue1 + "'" + "," + firstValue2 + "," + "'" + firstValue3 + "'" + "," + "'" + firstValue4 + "')" + ",";
> 
> >                     }
> else if (count > 250000 & count <= 500000)
> >                     {
> names1 += "(" + firstValue + "," + "'" + firstValue1 + "'" + "," + firstValue2 + "," + "'" + firstValue3 + "'" + "," + "'" + firstValue4 + "')" + ",";
> 
> count++;
> i++;
> >                 }`
> 
> swra.Stop();
> ms1.Text = Convert.ToString((swra.ElapsedMilliseconds));
> Stopwatch swra1 = new Stopwatch();
> swra1.Start();
> names = names.TrimEnd(',');
> names1 = names1.TrimEnd(',');
> 
> var cmdText = "INSERT INTO TEST Values (" + names + ")";
> var command = new OdbcCommand(cmdText, Conn);
> command.CommandTimeout = 0;
> command.ExecuteNonQuery();
> 
> cmdText = "INSERT INTO TEST Values (" + names1 + ")";
> command = new OdbcCommand(cmdText, Conn);
> command.CommandTimeout = 0;
> command.ExecuteNonQuery();`

Need to optimise the above code; above, I create a string of data and a stored name variable, but the above code will not work for more than 100 columns. Can you please help me figure out why I can't store values and insert them into the Hive table?

Thank you in advance.

c# asp.net hive odbc impala
© www.soinside.com 2019 - 2024. All rights reserved.