我有以下情况
SqlConnection sqlMdfCon = new SqlConnection();
sqlMdfCon.ConnectionString = "Data Source=" + txtDataSource.Text + ";Initial Catalog=" + txtDatabase.Text + ";Database=" + txtDatabase.Text + ";User ID=" + txtUserID.Text + ";Password=" + txtPassword.Text + ";Integrated Security=False";
if (sqlMdfCon.State == ConnectionState.Closed)
{
sqlMdfCon.Open();
}
dTable = sqlMdfCon.GetSchema("Tables");
foreach (DataRow DRow in dTable.Rows)
{
if (DRow["TABLE_TYPE"].ToString() == "TABLE" || DRow["TABLE_TYPE"].ToString() == "VIEW" || DRow["TABLE_TYPE"].ToString() == "BASE TABLE")
{
intPos = DRow["TABLE_NAME"].ToString().LastIndexOf("FilterDatabase");
lstTables.Items.Add(DRow["TABLE_NAME"]); // Getting error here
}
}
以下是例外
ConnectionString property is not initialized
为什么即使我已将连接字符串正确分配给连接,我也会得到这个?