Hi I'm currently doing a project using C#.net and sql server 2005, and I've run into a problem with a select statement! This select statment has to select all column names of a certain table (this is specified in the variable tablename) but i dont want it to include the column names of type int. Please could you help me with this? Here is the select statement i'm currently trying to us but get the error: "System.Data.SqlClient.SqlException: Invalid column name 'DATA_TYPE'." Code: cmd.CommandText = "SELECT [name] AS [Column name] FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE type = 'U' AND [NAME] = '" + tablename + "') AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')"; Thanks in advance!!
Dont give 2 select commands in one statement. as once one Query is running the other is not called .. as u initiated the first query second will not work. so use second to get the result and then put in 1st..
that's not the problem. as the error indicates the problem is with the select statement at "data_type" Invalid column name 'DATA_TYPE' if you check the columns for systables, do you see and column with name DATA_TYPE check here - http://msdn.microsoft.com/en-us/library/ms186816.aspx to check if your query runs properly, first execute the select statement in any sql client replacing the variables with values and then use it in the code