OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = customer.Properties.Settings.Default.Db;
OleDbDataAdapter sda = new OleDbDataAdapter(@"SELECT tbl_Customer.CustomerID,tbl_Customer_Trans.Date,tbl_Customer_Trans.DailyEntry,tbl_Customer_Trans.DailyInt, tbl_Customer_Trans.Fine
FROM tbl_Customer ,tbl_Customer_Trans
WHERE tbl_Customer.CustomerID = tbl_Customer_Trans.CustomerID;", conn);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.Rows.Clear();
foreach (DataRow item in dt.Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = item["CustomerID"].ToString();
dataGridView1.Rows[n].Cells[1].Value = item["Date"].ToString();
dataGridView1.Rows[n].Cells[2].Value = item["DailyEntry"].ToString();
dataGridView1.Rows[n].Cells[3].Value = item["DailyInt"].ToString();
dataGridView1.Rows[n].Cells[4].Value = item["Fine"].ToString();
int a = Convert.ToInt32(dataGridView1.Rows[n].Cells[2].Value);
int b = Convert.ToInt32(dataGridView1.Rows[n].Cells[3].Value);
int c = Convert.ToInt32(dataGridView1.Rows[n].Cells[4].Value);
int d = a + b + c ;
dataGridView1.Rows[n].Cells[5].Value = d;
}
当用户在文本框中输入Id时,只有输入的ID数据应该是可见的,如果用户输入ID = 1,那么在id 1上保存在表中的值应该是可见的。使用我的代码,所有值都存在于表是可见的