[英]Added some columns to a SQL Server 2008 R2 table but it does not show up when a web page queries the table
I've added some columns to a table in SQL Server 2008 R2. 我已经在SQL Server 2008 R2的表中添加了一些列。 I then put some default values into these columns.
然后,我在这些列中输入一些默认值。 Then I selected these columns with a query which produced the expected results in the output box.
然后,我通过查询选择了这些列,这些查询在输出框中产生了预期的结果。 My issue is when I use the following lines of code
我的问题是当我使用以下代码行时
if (ds.Tables[0].Rows[0]["abc"].ToString().Trim() == "")
{
this.abcHyperLink.ForeColor = Color.FromArgb(100, 100, 100);
}
else
{
this.abcHyperLink.NavigateUrl = ds.Tables[0].Rows[0]["abc"].ToString();
}
to query the new columns, it produces this error message 查询新列,它会产生此错误消息
Column 'abc' does not belong to table Table.
列“ abc”不属于表Table。
When I use the same code with old columns, the code works fine and retrieves the correct data. 当我对旧列使用相同的代码时,该代码可以正常工作并检索正确的数据。
Why can't I query the new columns but I can with the old columns? 为什么我不能查询新列,但可以查询旧列? Is there something else I have to do the new columns before I can query it with the code?
在使用代码查询之前,还需要做其他新列吗? Your help is much appreciated
非常感谢您的帮助
EDIT: 编辑:
The SQL query to check if the new columns were added is 用于检查是否添加了新列的SQL查询是
Select [abc],[xyy]
from [database].[dbo].[table]
EDIT2: The app calls EDIT2:该应用调用
public DataSet GetDataSet()
{
string sql = "use [name of db] exec sp_search_by '" + this.searchString + "'";
DataLayer dataLayer = new DataLayer();
return dataLayer.GetDataSet(sql, "BCITConn");
}
which calls 哪个电话
public DataSet GetDataSet(string sql, string db)
{
string providerName = ConfigurationManager.ConnectionStrings[db].ProviderName;
DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
DbConnection dbConnection = new SqlConnection();
try
{
dbConnection = factory.CreateConnection();
dbConnection.ConnectionString = ConfigurationManager.ConnectionStrings[db].ToString();
DbCommand dbCommand = factory.CreateCommand();
dbCommand.CommandText = sql;
dbCommand.CommandTimeout = 2000;
dbCommand.Connection = dbConnection;
DbDataAdapter dbDataAdapter = factory.CreateDataAdapter();
dbDataAdapter.SelectCommand = dbCommand;
DataSet dataSet = new DataSet();
dbDataAdapter.Fill(dataSet);
dbConnection.Close();
dbConnection.Dispose();
return dataSet;
}
catch (DbException ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
if (dbConnection != null)
{
dbConnection.Close();
dbConnection.Dispose();
}
}
return null;
}
which uses 使用
<connectionStrings>
<add name="BCITConn" connectionString="Data Source=[correct]; Initial Catalog=[name of db];User ID=[correct];Password=[correct]; Max Pool Size=1000000; pooling=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
from the web config 从网络配置
我唯一能想到的是您正在查询的列未呈现,或者您没有在查询中提及您的列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.