c# - 系统参数异常 : 'Keyword not supported: ' datasource'. '

标签 c#

每次运行代码时我都会遇到问题..这是我的代码:

SqlConnection con = new SqlConnection("DataSource=SQLSERVER;Bar_login; Integrated Security = True");
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter("select * from Bar_login where username = '" + txtuser.Text + "' and password ='" + txtpass.Text + "' ", con);
sda.Fill(dt);
if (dt.Rows.Count == 1)
{
    MessageBox.Show("Login Succesfully");
}
else
{
    MessageBox.Show("Wrong Username and Password");
}

它成功运行,但在登录过程之后..出现异常

unhandled.."System.ArgumentException: 'Keyword not supported: 'datasource'.'".

有人可以帮忙吗?

最佳答案

连接字符串中的“Data”和“Source”之间应该有一个空格。关键字是“Data Source”而不是“DataSource”。

关于c# - 系统参数异常 : 'Keyword not supported: ' datasource'. ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51907495/

相关文章:

c# - MdiContainer 表单未打开

c# - MVVM 使用 INotifyPropertyChanged Model 不通知 ViewModel

c# - 从 EF 获取平均值

c# - 服务总线主题插入了相同 MessageId 的重复消息记录

c# - C#中的继承和多态

c# - C# 中的“向后”公钥/私钥加密,我该怎么做?

c# - LINQ2SQL 实体构造函数约束

c# - 包含字符串的结构与包含字符串的类的性能

检查 Active Directory 域 Controller 是否已启动并正在运行的 C# 方法

c# - ASP.NET Core RC2 区域未发布