MySqlCommand cmd; // Получаем данные из таблицы testimony
cmd = con.CreateCommand();
cmd.CommandText = "SELECT Name FROM records";
con.Open();
List<string> array = new List<string>();
MySqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
array.Add(sdr.GetString(0));
}
con.Close();
string sqlQuery = "SELECT * FROM testimony WHERE Name IN({0})";
string parameters = "";
for (int i = 0; i < array.Count; i++)
{
parameters += "@record" + i + (i < array.Count - 1 ? ", " : "");
}
MySqlCommand cmd_FillTestimony; // Получаем данные из таблицы testimony
cmd_FillTestimony = con.CreateCommand();
cmd_FillTestimony.CommandText = string.Format(sqlQuery, parameters);
for (int i = 0; i < array.Count; i++)
{
cmd_FillTestimony.Parameters.AddWithValue("@record" + i, array[i]);
}
try
{
con.Open();
MySqlDataAdapter da_testimony = new MySqlDataAdapter(cmd_FillTestimony);
DataSet dataset_testimony = new DataSet();
da_testimony.Fill(dataset_testimony, "testimony");
report2.RegisterData(dataset_testimony.Tables["testimony"], "testimony");
(report2.Report.FindObject("Testimony_Data") as DataBand).DataSource = report2.GetDataSource("testimony");
report2.GetDataSource("testimony").Enabled = true;
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
report2.Show();
string sql = "SELECT * FROM testimony WHERE Name IN({0})";
string.Format(sql, parameters)
for (int i = 0; i < array.Length; i++)
{
cmd.Parameters.AddWithValue("@record" + (i + 1), array[i]);
}
SELECT * FROM testimony WHERE Name IN(@record1, @record2)