我遇到一個問題,插入我的SQL Server CE數據庫的一些數據到一個表。最終目標是把需要的值的列X,Y和Z,這樣我可以有另一種執行INNER JOIN
表,然後下拉列Q.的SQL Server CE插入拋出「表名稱是無效」
這裏是我的插入:
//Make the SQL query and set the parameters
SqlCeCommand SQLVarQ = connection.CreateCommand();
SQLVarQ.CommandText = "INSERT INTO Results (Value, Indx, Length) VALUES (@Var, @Ind, @Lng)";
SQLVarQ.CommandType = CommandType.TableDirect;
SQLVarQ.Parameters.Add("@Var", ThreadBuffer.SelectedText);
SQLVarQ.Parameters.Add("@Ind", ThreadBuffer.SelectionStart);
SQLVarQ.Parameters.Add("@Lng", Convert.ToInt32(varWordMatch.Length));
SQLVarQ.UpdatedRowSource = UpdateRowSource.Both;
using (SQLVarQ)
{
SQLVarQ.ExecuteNonQuery();
}
這是它引發的錯誤:
指定的表不存在。 [INSERT INTO結果(價值, INDX,長短)的值(@var,@Ind,@Lng)
任何人有任何想法,爲什麼這會發生?任何幫助深表感謝。
編輯:我知道,我創建的表,因爲這是僅高於其他代碼片段:
SqlCeCommand SqlTable = connection.CreateCommand();
SqlTable.CommandText = "CREATE TABLE Results (Value NVARCHAR, Indx INT, Length INT, Data NVARCHAR)";
using (SqlTable)
{
try
{
SqlTable.ExecuteNonQuery();
}
catch
{
MessageBox.Show("The Table already exists");
}
}
「任何人有任何想法,爲什麼會是這樣嗎?」:好,可能是因爲該表不存在... – 2012-02-03 21:55:11
後使用'()'你不需要一個dispose()了。並且,如果沒有很好的,非常特殊的原因,不要調用GC.Collect()。 – 2012-02-03 21:57:55
你可以顯示什麼實際的SQL Server連接字符串看起來像.config文件中的CommandType.TableDirect不應該是CommandType.Text也... ..? – MethodMan 2012-02-03 21:58:53