本文介绍了数据转换失败问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我遇到数据转换失败的问题,我无法确定为什么会发生这种情况。



(对此代码的长度表示歉意)。

这是我到目前为止的代码:



Hi everyone!

I am running into an issue with data conversion failing that I cannot pinpoint as to why this is happening.

(My apologies for the length of this code).
Here is the code that I have so far:

if (File.Exists("C:\\Program Files (x86)\\Pico Technology\\TMS\\PicoScope.exe"))
{
     SqlCeCommand tableNameGeneratorCommand = new SqlCeCommand("SELECT table_name FROM information_schema.tables WHERE (table_name <> 'docfiles') AND (table_name <> 'waveform_files') AND " + "(table_name <> 'vehicles') AND (table_name <> 'accountmanagement') AND (table_name <> 'engineandtransmissioncodes') AND (table_name != 'enginecodemaster') AND (table_name != 'transmissioncodemaster')", conn);
     tableNameGeneratorCommand.CommandType = CommandType.Text;
     SqlCeDataReader tableNameGeneratorCommand_dr = tableNameGeneratorCommand.ExecuteReader();

     while (tableNameGeneratorCommand_dr.Read())
     {
          SqlCeCommand columnNameGeneratorCommand = new SqlCeCommand("SELECT DISTINCT column_name FROM information_schema.columns " + "WHERE (table_name <> 'docfiles') AND (table_name <> 'waveform_files') AND (table_name <> 'vehicles') AND (table_name <> 'engineandtransmissioncodes') " + "AND (column_name <> 'vehicle_key') AND table_name = @table_name", conn);

          columnNameGeneratorCommand.CommandType = CommandType.Text;
          columnNameGeneratorCommand.Parameters.AddWithValue("@table_name", tableNameGeneratorCommand_dr.GetString(0));
          SqlCeDataReader columnNameGeneratorCommand_dr = columnNameGeneratorCommand.ExecuteReader();

          while (columnNameGeneratorCommand_dr.Read())
          {
               SqlCeCommand keyCommand = new SqlCeCommand("SELECT 'SELECT DISTINCT ' + [2] + ' FROM ' + [1] FROM __sysobjects WHERE [1] = @TableName AND [2] = @ColumnName", conn);
               keyCommand.CommandType = CommandType.Text;
               keyCommand.Parameters.AddWithValue("@TableName", tableNameGeneratorCommand_dr.GetString(0));
               keyCommand.Parameters.AddWithValue("@ColumnName", columnNameGeneratorCommand_dr.GetString(0));
               keyCommand.ExecuteNonQuery();

               SqlCeDataReader keyCommand_dr = keyCommand.ExecuteReader();

               while (keyCommand_dr.Read())
               {
                    SqlCeCommand keyCommandPrime = new SqlCeCommand(keyCommand_dr.GetString(0) + " LEFT OUTER JOIN vehicles ON " + tableNameGeneratorCommand_dr.GetString(0) + "." + columnNameGeneratorCommand_dr.GetString(0) +
                    " = Vehicles.[KEY] WHERE make = @make AND model = @model AND year = @year AND engine_code = @engine_code AND transmission_code = @transmission_code", conn);
                    keyCommandPrime.CommandType = CommandType.Text;
                    keyCommandPrime.Parameters.AddWithValue("@make", Convert.ToString(makeComboBox.SelectedItem));
                    keyCommandPrime.Parameters.AddWithValue("@model", Convert.ToString(modelComboBox.SelectedItem));
                    keyCommandPrime.Parameters.AddWithValue("@year", Convert.ToString(yearComboBox.SelectedItem));
                    keyCommandPrime.Parameters.AddWithValue("@engine_code", Convert.ToString(engineCodeComboBox.SelectedItem));
                    keyCommandPrime.Parameters.AddWithValue("@transmission_code", Convert.ToString(transmissionCodeComboBox.SelectedItem));
                    keyCommandPrime.ExecuteNonQuery();

                    SqlCeDataReader keyCommandPrime_dr = keyCommandPrime.ExecuteReader();

                    try
                    {
                         while (keyCommandPrime_dr.Read())
                         {
                              MessageBox.Show(keyCommandPrime_dr.GetString(0));
                         }
                    }
                    catch (Exception ex)
                    {
                         MessageBox.Show(ex.Message);
                    }
               }
          }
     }
}





问题我收到的是我收到此消息数据转换失败。[OLE DB状态值(如果已知)= 2]



此行未通过。

while(keyCommandPrime_dr.Read())

所有5个参数来自5个组合框以及此函数触发前的选择。



有谁知道我错过了什么?我看不出问题。



The issue I am having is I get this message "Data conversion failed. [ OLE DB status value (if known) = 2 ]

It is failing on this line.
while (keyCommandPrime_dr.Read())
All 5 parameters are coming from 5 comboboxes and what the selections are before this function is fired.

Does anyone know what I''m missing? I can''t see the problem.

推荐答案


这篇关于数据转换失败问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 02:52