我正在尝试从字符串数组中选择一个随机元素并将其保存在我的数据库中。
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++;
}
这没用。