本文整理汇总了C#中System.Convert.IsDBNull方法的典型用法代码示例。如果您正苦于以下问题:C# Convert.IsDBNull方法的具体用法?C# Convert.IsDBNull怎么用?C# Convert.IsDBNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Convert
的用法示例。
在下文中一共展示了Convert.IsDBNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Form1_Load
private void Form1_Load(object sender, EventArgs e)
{
// Define ADO.NET objects.
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
SqlDataReader dr;
// Open connection, and retrieve dataset.
conn.Open();
// Define Command object.
cmd.CommandText = "Select * From Responses";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
// Retrieve data reader.
dr = cmd.ExecuteReader();
int fieldCount = dr.FieldCount;
object[] fieldValues = new object[fieldCount];
string[] headers = new string[fieldCount];
// Get names of fields.
for (int ctr = 0; ctr < fieldCount; ctr++)
headers[ctr] = dr.GetName(ctr);
// Set up data grid.
this.grid.ColumnCount = fieldCount;
this.grid.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy;
this.grid.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
this.grid.ColumnHeadersDefaultCellStyle.Font = new Font(this.grid.Font, FontStyle.Bold);
this.grid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
this.grid.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
this.grid.CellBorderStyle = DataGridViewCellBorderStyle.Single;
this.grid.GridColor = Color.Black;
this.grid.RowHeadersVisible = true;
for (int columnNumber = 0; columnNumber < headers.Length; columnNumber++)
this.grid.Columns[columnNumber].Name = headers[columnNumber];
// Get data, replace missing values with "NA", and display it.
while (dr.Read())
{
dr.GetValues(fieldValues);
for (int fieldCounter = 0; fieldCounter < fieldCount; fieldCounter++)
{
if (Convert.IsDBNull(fieldValues[fieldCounter]))
fieldValues[fieldCounter] = "NA";
}
grid.Rows.Add(fieldValues);
}
dr.Close();
}