0
私のアプリケーションは、SQLクエリテーブルを読み込み、リストビューの特定のフィールドに値を照合して表示しています。私のクエリのSQLテーブルは次のようになりますの問題SQLテーブルC#
+--------------+---------+-------+----------+--------+ | process name | subtask | total | employee | date | +--------------+---------+-------+----------+--------+ | process 1 | sub1 | 1 | 1111 | 01-May | | process 2 | | 1 | 2222 | 05-May | | process 3 | | 1 | 3333 | 10-May | | process 4 | | 1 | 4444 | 07-May | +--------------+---------+-------+----------+--------+
私は問題に遭遇しました。私は私のループ(messegeboxを使用して)私のメッセージボックスに複数回(MessageBox.Show(dr[0].ToString());
)1回だけ表示する必要があり、ループがプロセス4に表示されるときにプロセス4 MessageBox.Show(dr[0].ToString());
))ループが停止するため、合計、従業員および日付の値は取得されません。どうしたらいいですか?
DateTime now = DateTime.Now;
var startDate = new DateTime(now.Year, now.Month, 1);
var endDate = startDate.AddMonths(1).AddDays(-1);
string[,] report = new string[,] { {"process 1", "sub1", "3", "0", "", "" },
{"process 2", "", "3", "0", "", "" },
{"process 3", "", "3", "0", "", "" }
*** there are multiple entries in this array *****
}
string totalsquery = "select Process_Name, Sub_Process1_Name, count(id) as total, Completed_By_Employee_Number, max(Refresh_Date) from testDB.dbo.Quality_Data_Master where Refresh_Date between '" + startDate + "' and '" + endDate + "' group by Process_Name, Sub_Process1_Name, Completed_By_Employee_Number, Refresh_Date";
SqlConnection con = new SqlConnection();
SqlDataAdapter ada = new SqlDataAdapter(totalsquery, con);
DataTable dt = new DataTable();
ada.Fill(dt);
listView1.View = View.Details;
listView1.Columns.Add("Process Name", 250);
listView1.Columns.Add(" Sub Task", 200);
listView1.Columns.Add("Target", 45, HorizontalAlignment.Center);
listView1.Columns.Add("Total", 40, HorizontalAlignment.Center);
listView1.Columns.Add("Employee", 100, HorizontalAlignment.Center);
listView1.Columns.Add("Date", 100);
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
//MessageBox.Show(dr.ToString());
for (int j = 0; j < report.GetLength(0); j++)
{
if (report[j, 0].Equals(dr[0].ToString()))
{
MessageBox.Show(dr[0].ToString());
if (report[j, 1].Equals(dr[1].ToString()))
{
MessageBox.Show(dr[1].ToString());
report[j, 3] = (Int32.Parse(report[j, 3]) + (int)dr[2]).ToString();
MessageBox.Show(dr[2].ToString());
report[j, 4] = report[j, 4] + dr[3].ToString();
MessageBox.Show(dr[3].ToString());
report[j, 5] = report[j, 5] + dr[4].ToString();
MessageBox.Show(dr[4].ToString());
}
}
}
}
String[] temp = new String[7];
for (int i = 0; i < report.GetLength(0); i++)
{
temp[0] = report[i, 0].ToString();
temp[1] = report[i, 1].ToString();
temp[2] = report[i, 2].ToString();
temp[3] = report[i, 3].ToString();
temp[4] = report[i, 4].ToString();
temp[5] = report[i, 5].ToString();
//temp[6] = report[i, 6].ToString();
ListViewItem listItem = new ListViewItem(temp);
listView1.Items.Add(listItem);
}
con.Close();
あなたの全体のループがどこにも定義されていない変数「レポート」と連携し、またクエリがどこにも示されています。だから、これは検索を開始する場所だと思われます。あなたは「報告書」の争点をチェックしましたか? – Fuzzzzel
レポートは配列です。私はコードにこれを追加します。ありがとうございました – bleeetiso
完全な'report'変数をペーストしたかどうかわかりませんが、これは私が見ているものです: 'string [、] report = newあなたが最後の '}'を忘れてしまったと仮定することができます。この場合、あなたはあなたには '' 2次元配列ですが、一方の次元には1つのアイテム(6つのアイテムの配列)があり、もう一方の次元は空です。 'report.GetLength(0)'を 'report.GetLength(1)'に変更する必要があることを修正すると思います。 –