在SQL Server 2008 R2表中添加了一些列,但在网页查询表时没有显示(Added some columns to a SQL Server 2008 R2 table but it doe

编程入门 行业动态 更新时间:2024-10-15 00:20:00
在SQL Server 2008 R2表中添加了一些列,但在网页查询表时没有显示(Added some columns to a SQL Server 2008 R2 table but it does not show up when a web page queries the table)

我在SQL Server 2008 R2中的表中添加了一些列。 然后我将一些默认值放入这些列中。 然后,我使用查询选择了这些列,该查询在输出框中生成了预期结果。 我的问题是当我使用以下代码行时

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(); }

要查询新列,它会生成此错误消息

列'abc'不属于表Table。

当我对旧列使用相同的代码时,代码工作正常并检索正确的数据。

为什么我不能查询新列,但我可以使用旧列? 在我用代码查询之前,还有什么我需要做的新列吗? 非常感谢您的帮助

编辑:

用于检查是否添加了新列的SQL查询是

Select [abc],[xyy] from [database].[dbo].[table]

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"); }

哪个叫

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; }

使用

<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>

来自网络配置

I've added some columns to a table in 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.

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

Select [abc],[xyy] from [database].[dbo].[table]

EDIT2: The app calls

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

最满意答案

我唯一能想到的是你要查询的列没有被渲染,也许你没有在查询中提到你的列。

The only thing I can think of is that the column you are querying is not being rendered perhaps you aren't mentioning your column in the query.

更多推荐

本文发布于:2023-08-01 01:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1350624.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:但在   网页   SQL   Server   Added

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!