c# - [InvalidCastException : Unable to cast object of type 'System.DBNull' to type 'System.String' .]

标签 c# asp.net string session ms-access

<分区>

错误行:

来源错误:

Line 37:         while (rdr.Read()==true)
Line 38:         {
Line 39:             if (TextBoxUserName.Text == (string)rdr["CUserName"]) 
Line 40:             {
Line 41:                 ClientScript.RegisterStartupScript(csType,"Error",scriptErrorUserId);

当我尝试注册帐户时弹出。

我使用 Microsoft Access 作为数据库。

数据库 - CUserName session - sUserName 还有@eUserName

有什么想法吗?

最佳答案

替换这个

if (TextBoxUserName.Text == (string)rdr["CUserName"])

if (TextBoxUserName.Text == rdr["CUserName"].ToString())

关于c# - [InvalidCastException : Unable to cast object of type 'System.DBNull' to type 'System.String' .],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21216641/

相关文章:

c# - 我可以实现 DisposeBase 抽象类吗?

c# - 声明一个类作为它自己的成员

c++ - 仅选择字符串 C++ 中的前几个字符

来自字符串的 C++ 字节数组

wstring 的 C++ 句柄

c#静态类和非静态类有什么区别(我说的是类本身不是字段)

c# - 以编程方式发送 Salesforce Web 至潜在客户表单数据

asp.net - FindControl 并将文本框更改为整数?

c# - 为什么我可以在 web.config 中有多个相同的绑定(bind)重定向?

c# - 在 asp 和 c#/javascript 中创建帮助按钮