我正在尝试创建一个SQL查询并将结果保存在XML文件中,但是我得到的错误就像我附在这里的图片一样 无效栏! 此查询在SQL服务器中正常工作但不在此处
namespace xxxxxxxxxxxx
{
public partial class MainWindow : Window
{
string vinValue;
string operationValue;
string serviceValue;
public MainWindow()
{
InitializeComponent();
}
private void FrameLoad_Activated(object sender, EventArgs e)
{
}
private void btnGo_Click(object sender, RoutedEventArgs e)
{
DataSet ds = new DataSet();
SqlDataAdapter adapter;
string sql = String.Format("SELECT FGACJD_Vin_Ecu.Vin,FGACJD_Vin_Ecu.NHard,"+
"FGACJD_Vin_Ecu.NVerHard,FGACJD_Vin_Ecu.NSoft,FGACJD_Vin_Ecu.NVerSoft,"+
"InfoProg_wiTECH_Global.NHard,InfoProg_wiTECH_Global.NVerHard,"+
"InfoProg_wiTECH_Global.NSoft,InfoProg_wiTECH_Global.NSoftNew,"+
"InfoProg_wiTECH_Global.NVerSoft,InfoProg_wiTECH_Global.NomeFile,"+
"InfoProg_wiTECH_Associa.KeyJoined,InfoProg_wiTECH_Associa.MakeID,"+
"InfoProg_wiTECH_Associa.ModelID,InfoProg_wiTECH_Associa.Model_Type "+
"FROM FGACJD_Vin_Ecu, InfoProg_wiTECH_Global,InfoProg_wiTECH_Associa "+
"WHERE [FGACJD_Vin_Ecu.Vin]='{0}'"+
" AND InfoProg_wiTECH_Associa.KeyJoined = InfoProg_wiTECH_Global.NomeFile"+
" AND FGACJD_Vin_Ecu.NHard=InfoProg_wiTECH_Global.NHard"+
" AND InfoProg_wiTECH_Global.NVerHard like '%'+FGACJD_Vin_Ecu.NVerHard "+
"FOR XML PATH('flash'), ROOT ('FlashList ')", vinValue);
//TextOutput.Text = sql;
string connectionString = "user id=xxx;password=xxx;"+
"server=localhost;" +
"Trusted_Connection=yes;" +
"database=xxx; " +
"connection timeout=30";
SqlConnection conn = new SqlConnection(connectionString);
try
{
conn.Open();
}
catch (Exception)
{
string err = "Database error contact administrator";
MessageBox.Show(err, "Error!");
}
try
{
adapter = new SqlDataAdapter(sql, conn);
adapter.Fill(ds);
conn.Close();
ds.WriteXml("Product.xml");
MessageBox.Show("Done");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void TextInput_TextChanged(object sender, TextChangedEventArgs e)
{
vinValue = TextInput.Text;
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var comboBox = sender as ComboBox;
serviceValue = comboBox.SelectedItem as string;
this.Title = "Selected: " + serviceValue;
}
private void ComboBox_Loaded(object sender, RoutedEventArgs e)
{
List<string> data = new List<string>();
data.Add("getFlashListByVIN");
var comboBox = sender as ComboBox;
comboBox.ItemsSource = data;
comboBox.SelectedIndex = 0;
}
private void Operation_Loaded(object sender, RoutedEventArgs e)
{
List<string> data = new List<string>();
data.Add("MOC");
var comboBox = sender as ComboBox;
comboBox.ItemsSource = data;
comboBox.SelectedIndex = 0;
}
private void Operation_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var comboBox = sender as ComboBox;
operationValue = comboBox.SelectedItem as string;
this.Title = "Selected: " + operationValue;
}
}
}
我收到此错误
System.Data.SqlClient.SqlException(0x80131904):列名无效 'FGACJD_Vin_Ecu.Vin'。在 System.Data.SqlClient.SqlConnection.OnError(SqlException异常, 布尔值breakConnection,Action
1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action
1 wrapCloseInAction)at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj,Boolean callerHasConnectionLock,Boolean asyncClose)at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler,SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,布尔&amp; dataReady)at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()at System.Data.SqlClient.SqlDataReader.get_MetaData()at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior,String resetOptionsString)at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(的CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async,Int32超时,任务&amp; task,Boolean asyncWrite,SqlDataReader ds)at System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String 方法,TaskCompletionSource`1完成,Int32超时,任务&amp;任务, 布尔asyncWrite)at System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String 方法)at System.Data.SqlClient.SqlCommand.ExecuteReader(的CommandBehavior 行为,String方法)at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(的CommandBehavior 行为) System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(的CommandBehavior 在System.Data.Common.DbDataAdapter.FillInternal(DataSet。)的行为) dataset,DataTable [] datatables,Int32 startRecord,Int32 maxRecords, 字符串srcTable,IDbCommand命令,CommandBehavior行为)at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令, CommandBehavior行为)at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)at FlashListByVinLadan.MainWindow.btnGo_Click(对象发送者, RoutedEventArgs e)in C:\用户\ Finsoft \桌面\测试\ FlashListByVinLadan \ FlashListByVinLadan \ MainWindow.xaml.cs:线 80 ClientConnectionId:3653b64e-bb82-41cb-8fc8-4d92fbaa3c3e错误 数:207,状态:1,类别:16
答案 0 :(得分:0)
sql错误
WHERE FGACJD_Vin_Ecu.Vin='{0}'