“值不能为null.\\参数名称:providerinvariantname”,在C#窗体中,错误dbprovider factorie(dataprovider name)not null如何修复这些 [英] "Value cannot be null.\r\nparameter name: providerinvariantname"}, in C# windows form, error dbprovider factorie (dataprovider name) not null how fix these

查看:275
本文介绍了“值不能为null.\\参数名称:providerinvariantname”,在C#窗体中,错误dbprovider factorie(dataprovider name)not null如何修复这些的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   static  DbCommand CreateCommand()
{
// WebConfigReader
/ / 获取数据库提供者名称
string dataProviderName = WebConfigReader.DbProviderName;
// 获取数据库连接字符串
string connectionString = WebConfigReader.DbConnectionString;
// 创建新的数据提供者工厂
DbProviderFactory factory = DbProviderFactories.GetFactory (dataProviderName);
// 获取数据库特定的连接对象
DbConnection conn = factory.CreateConnection ();
// 设置连接字符串
conn.ConnectionString = connectionString;
// 创建特定于数据库的命令对象
DbCommand comm = conn.CreateCommand ();
// 将命令类型设置为存储过程
comm.CommandType = CommandType .StoredProcedure;
// 返回初始化的命令对象
返回 comm;
}
}
}





我尝试了什么:



i尝试更改dbprovider名称和连接字符串如何修复

解决方案

查看错误消息:

值不能为空。 
参数名称:providerinvariantname



这是来自您的数据库,意味着您尝试在声明为的列上插入或更新具有空值的列NOT NULL。



我们无法解决这个问题:这是你的数据库,还有你的数据!允许空值 - 在这种情况下更改您的数据库 - 或者它们不是 - 在这种情况下清理您的数据输入。

我们不能为您执行任何操作...


错误消息表明 WebConfigReader.DbProviderName 正在返回 null 。您需要调试代码以找出原因。


public static DbCommand CreateCommand()
{ 
            //WebConfigReader 
            // Obtain the database provider name
            string dataProviderName = WebConfigReader.DbProviderName;
            // Obtain the database connection string
            string connectionString = WebConfigReader.DbConnectionString;
            // Create a new data provider factory
            DbProviderFactory factory = DbProviderFactories.GetFactory(dataProviderName);
            // Obtain a database specific connection object
            DbConnection conn = factory.CreateConnection();
            // Set the connection string
            conn.ConnectionString = connectionString;
            // Create a database specific command object
            DbCommand comm = conn.CreateCommand();
            // Set the command type to stored procedure
            comm.CommandType = CommandType.StoredProcedure;
            // Return the initialized command object
            return comm;
        }
    }
}



What I have tried:

i tried to change dbprovider name and connection string how to fix

解决方案

Look at the error message:

Value cannot be null.
parameter name: providerinvariantname


That is coming from your DB and means that you are trying to insert or update a column with a null value on a column declared as NOT NULL.

We can't fix that: it's your DB, and your data! Either nulls are allowed - in which case change your DB - or they aren't - in which case sanitize your data inputs.
We can't do any of that for you...


The error message would suggest that WebConfigReader.DbProviderName is returning null. You'll need to debug your code to find out why.


这篇关于“值不能为null.\\参数名称:providerinvariantname”,在C#窗体中,错误dbprovider factorie(dataprovider name)not null如何修复这些的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆