2011-10-30 12 views
-1

この関数は、「接続が正しく初期化されていません」というエラーを表示します。どうして?クエリを実行しない:接続が正しく初期化されていない

public void updateCustomer() 
{ 
    using (SqlCeConnection aConnection = new SqlCeConnection(@"Data Source=|DataDirectory|\Database.sdf")) 
    { 
      aConnection.Open(); 
      using (SqlCeCommand aCommand = new SqlCeCommand("UPDATE customer SET credit = @credit WHERE(ID = @ID)")) 
      { 
       aCommand.Parameters.Add(new SqlCeParameter("credit", SqlDbType.NVarChar, 100)).Value = getRemaining(); 
       aCommand.Parameters.Add(new SqlCeParameter("ID", SqlDbType.Int, 8)).Value = Convert.ToInt32(textBox2.Text); 

       int resultUpdate = aCommand.ExecuteNonQuery(); 
       if (resultUpdate != -1) 
        label9.Text = "customer updated sussessfully"; 
       else 
        label9.Text = "some error in updating customer"; 
       aConnection.Close(); 
      } 
    } 
} 

答えて

-1

ため

@"Data Source=|DataDirectory|\Database.sdf;Persist Security Info=False;" 

チェックConnection strings for SQL Server Compact EditionとしてSqlCeCommand

SqlCeCommand command = new SqlCeCommand(
    queryString, connection); 

セットの接続文字列の接続を設定する必要があります

使用しているSqlCommandオブジェクトには、引数として詐欺を望んでいる時はいつでもするたび.rememeber倍の多く

...

そうSqlDataAdapterオブジェクトという名前の、より高度なユーティリティを使用して...

関連する問題