这是我的代码的NullReferenceException是未处理显示在datagridview的设置栏
connection.Open();
try
{
adpSup.SelectCommand = new SqlCommand("SELECT Supplier_Supplier AS 'Supplier', Supplier_TP AS 'Telephone', Supplier_EMail AS 'E-Mail', Supplier_Address AS 'Address' FROM Supplier", connection);
dsSup.Clear();
adpSup.Fill(dsSup, "tblSupplier");
dgSupplier.DataSource = dsSup.Tables["tblSupplier"];
dgSupplier.Columns["Telephone"].Width = 70;
foreach (DataGridViewColumn col in dgSupplier.Columns)
{
col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
col.HeaderCell.Style.Font = new Font("Arial", 12F, FontStyle.Bold, GraphicsUnit.Pixel);
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message, "Report", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
}
finally
{
connection.Close();
}
的宽度时,当我运行这段代码它显示“类型‘System.NullReferenceException’未处理的异常发生在System.Windows。 Forms.dll其他信息:对象引用未设置为对象的实例。“ 我不知道什么是错误的,请帮我
仍然会出现问题。在这条线上显示的问题 'dgSupplier.Columns [“Telephone”]。Width = 70;' – kavi 2014-08-31 00:50:25