文字列の配列からランダムな要素を選択してデータベースに保存しようとしています。
OleDbConnection myConnection = new OleDbConnection(connectionString);
myConnection.Open();
string Update = string.Format("UPDATE Ships SET InPort=True");
OleDbCommand myCommandUpdt = new OleDbCommand(Update);
myCommandUpdt.Connection = myConnection;
myCommandUpdt.ExecuteNonQuery();
OleDbDataReader drdrShipsRead = myCommandUpdt.ExecuteReader();
string[] Randominporta = { "True", "False", "False" };
// Testlabel.Text = Convert.ToString(Randominport[randomNumber]);
int iNumber = 1;
while (drdrShipsRead.Read())
{
int randomNumber = random.Next(0, 3);
string myAddingQuery = string.Format(" UPDATE Ships SET InPort= " + Convert.ToString(Randominport[randomNumber]) + " WHERE ID= " + iNumber + "");
OleDbCommand myCommand = new OleDbCommand(myAddingQuery);
string myCommand.Connectionresult = myConnection;
myCommand.ExecuteNonQuery();
iNumber++;
}
それは動作しません。