這是我的代碼的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