none
Multiple lines SQL statement and DataAdapter. RRS feed

  • Question

  • hello

    If my sql statement has multiple lines with comments (i.e. line starting with "//") - how am I going to get it work with Sql cmd and Adapters...? Is there a carriage return escape character ...?

                      Cmd = Conn.CreateCommand();
                      Cmd.CommandType = CommandType.Text;
                      Cmd.CommandTimeout = 0;
                      Cmd.CommandText = SomeSQL; << This is multiple lines concatenate to a single string.
    ConnFactory = DbProviderFactories.GetFactory("System.Data.SqlClient"); SomeDataSet = new DataSet("MultilineSQL"); SomeTable = new DataTable("MultilineSQL"); SomeDataSet.Tables.Add(SomeTable); DbAdapter = ConnFactory.CreateDataAdapter(); DbAdapter.SelectCommand = (DbCommand)Cmd; DbAdapter.Fill(OutputSet, "MultilineSQL");

    Thanks

     

    Thursday, May 13, 2010 4:22 AM

Answers

  • Hi,

    Which database are you using?   For SQL Server T-SQL, “--” is used to represent the comments in the SQL commands.   Multiple lines SQL statement will work fine for SqlDataAdapter.    The single string may contain some carriage return escape character like “\r\n” in C#.  

    Do you encounter any issues or exceptions?   If you have any questions, please feel free to let us know.

    Have a nice day!


    Lingzhi Sun
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact
    msdnmg@microsoft.com. 

    P.S.  I will move this thread to dataset forum since it is not a Entity Framework problem. 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, May 13, 2010 4:28 PM
    Moderator
  • THanks but I found a very simple soln' i've overlooked - just removes lines with comment from sql statemetns/scripts before concatenating them to one single line
    Friday, May 14, 2010 3:53 AM

All replies