使用oledbdatareader取得数据库上的数据的时候,要判断一下是数据库中这个值是否是空值,如果是空值出引发一个异常
int iename = myReader.GetOrdinal("ename");
int iurls = myReader.GetOrdinal("urls");
int iquyu = myReader.GetOrdinal("quyu");
int iregstr1 = myReader.GetOrdinal("regstr1");
int iregstr2 = myReader.GetOrdinal("regstr2");
string squyu, sregstr1, sregstr2;
while (myReader.Read())
{
string sename = myReader.GetString(iename);
string surls = myReader.GetString(iurls);
if (myReader.IsDBNull(iquyu))
squyu = "";
else
squyu = myReader.GetString(iquyu);
if (myReader.IsDBNull(iregstr1))
sregstr1 = "";
else
sregstr1 = myReader.GetString(iregstr1);
if (myReader.IsDBNull(iregstr2))
sregstr2 = "";
else
sregstr2 = myReader.GetString(iregstr2);
Debug.WriteLine(sename);
Debug.WriteLine(surls);
Debug.WriteLine(squyu);
Debug.WriteLine(sregstr1);
Debug.WriteLine(sregstr2);
}