使用MySQL数据库:

c# - C#我的datagridview列显示错误的年份-LMLPHP

我的DataGridView结果:

c# - C#我的datagridview列显示错误的年份-LMLPHP

我的密码

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);

最佳答案

您可以将DataFormatString =“ {0:yyyy / MM / dd}”用于gridview。

关于c# - C#我的datagridview列显示错误的年份,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36214220/

10-10 07:20