C#my datagridview列显示错误的一年

时间:2016-03-25 04:53:21

标签: c# mysql datagridview

使用MySQL数据库:

enter image description here

我的DataGridView结果:

enter image description here

我的代码

MySqlCommand cmd = new MySqlCommand("SELECT Invoices.InvoiceDate,InvoiceDetail.ProductName,InvoiceDetail.Quantity,InvoiceDetail.Discount FROM Invoices INNER JOIN InvoiceDetail ON Invoices.InvoiceID=InvoiceDetail.InvoiceID WHERE Invoices.CustomersID='" + textBox1.Text + "'", con);

MySqlDataAdapter sda = new MySqlDataAdapter();
sda.SelectCommand = cmd;

DataTable dt = new DataTable();
sda.Fill(dt);

BindingSource bs = new BindingSource();
bs.DataSource = dt;

dataGridView1.DataSource = bs;
dataGridView1.Columns[0].DefaultCellStyle.Format = "yyyy/MM/dd";

sda.Update(dt);

1 个答案:

答案 0 :(得分:0)

您可以对gridview使用 DataFormatString =“{0:yyyy / MM / dd}”