c# 如何判断记录的某个字段值为空?

来源:百度知道 编辑:UC知道 时间:2024/06/08 15:32:56
我用c# 读取sql 2000 的一个表格table1的一个记录,记录的某个字段score 可能为空值,那么 假设我读出的值是:ds.Tables[0].Rows[0]["score "],
请问怎样判断ds.Tables[0].Rows[0]["score "]是否为空值??
我记得不是用null判断的,好像也不是isEmpty判断

if(!ds.Tables[0].Rows[0]["score "].Equals(DBNull.Value))

if (ds.Tables[0].Rows[0]["score "]=DBNull.Value)
{
//为空
}
else
{
//有值
}

if(ds.Tables[0].Rows[0]["score "].toString()=="")

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication16
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataSet ds = new DataSet();
private SqlDataAdapter da;
private void Form1_Load(object sender, EventArgs e)
{
//连接字符串, 你自己修改一下登录名和数据库名.我的数据库名是kk
string connStr = @"Data Source=FLOWER\YNG;