1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help with sql select query

Discussion in 'Database' started by murlock1988, Aug 16, 2009.

  1. murlock1988

    murlock1988 New Member

    Joined:
    Aug 16, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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!!
     
  2. night.rider

    night.rider New Member

    Joined:
    Jul 13, 2009
    Messages:
    14
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    create and implement Logic..
    Location:
    somewhere
    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..
     
  3. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    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
     

Share This Page