• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

DataTable in Coldfusion (in cfscript)

New Here ,
Apr 29, 2014 Apr 29, 2014

Copy link to clipboard

Copied

Hi i want to add DataTable in Coldfusion script...Like c# code...C# code is following:

                    

                   DataTable productPropertyFilterTable = new DataTable();

                    productPropertyFilterTable.Columns.Add("RowID", typeof(int));

                    productPropertyFilterTable.Columns.Add("PropertyId", typeof(long));

                    productPropertyFilterTable.Columns.Add("PropertyWeight", typeof(string));

                    productPropertyFilterTable.Columns.Add("LowerRange", typeof(float));

                    productPropertyFilterTable.Columns.Add("UpperRange", typeof(float));

Views

960

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Apr 30, 2014 Apr 30, 2014

You want to use QueryNew and QueryAddColumn.

productPropertyFilterTable  = queryNew('');

queryAddColumn(productPropertyFilterTable, 'RowID', 'Integer');

queryAddColumn(productPropertyFilterTable, 'PropertyWeight', 'VarChar');

Alternatively you can just do the same with QueryNew on its own.

productPropertyFilterTable  = queryNew('RowID,PropertyWeight', 'Integer,VarChar');

Votes

Translate

Translate
Engaged ,
Apr 30, 2014 Apr 30, 2014

Copy link to clipboard

Copied

You want to use QueryNew and QueryAddColumn.

productPropertyFilterTable  = queryNew('');

queryAddColumn(productPropertyFilterTable, 'RowID', 'Integer');

queryAddColumn(productPropertyFilterTable, 'PropertyWeight', 'VarChar');

Alternatively you can just do the same with QueryNew on its own.

productPropertyFilterTable  = queryNew('RowID,PropertyWeight', 'Integer,VarChar');

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

How to add data in datatabel like C# Code:

productPropertyFilterTable.Rows.Add(i, wordsStrings[0], wordsStrings[3], Limit[0], Limit[1]);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

Now you need to use QueryAddRow and QuerySetCell

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

I try to use

QueryAddRow and QuerySetCell

queryAddRow(productPropertyFilterTable,1);

querySetCell(productPropertyFilterTable,RowID,i,1);


but its not work....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

That second line you need to quote the column name:

querySetCell(productPropertyFilterTable, "RowID", i, 1);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

Thanks...Its work....

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

Hi i have another issue...How can i write this c# code in coldfusion(Script).....

var warnings = new SqlParameter("ProductPropertyFilter", SqlDbType.Structured);

                        warnings.Value = productPropertyFilterTable;

                        warnings.TypeName = @"[dbo].[ProductPropertyFilter]";

                        using (var ctx = new ProductBookEntities())

                        {

                            var productFilter = ctx.Database.SqlQuery<ProductFilter>("dbo.FindScore @ProductPropertyFilter",

                               warnings);

                            dataProducts = productFilter.ToList();

                            if (dataProducts.Count() > range)

                            {

                                dataProducts = dataProducts.OrderByDescending(x => x.Score).Take(range).ToList();

                            }

                            ctx.Dispose();

                        }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

You probably want to start by reading up on some CF documentation of how to do queries.  Start here:

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 01, 2014 May 01, 2014

Copy link to clipboard

Copied

LATEST

remote function Retrieve(string dataLists)

          {

myQry = new Query();

myQry.setSQL("SELECT * FROM Product");

myQuery = myQry.execute();

dataProducts=myQuery.getResult();

dataProducts1=serializeJSON(dataProducts);

return dataProducts;

}

I call this method by using following code::

read: {

          type:"POST",

         url: "Controllers/Home.cfc",

         dataType: "json",

         data: {

                 method: "Retrieve",

                 dataLists: JSON.stringify(request)

                  }

        }

I want to return dataProducts or dataProducts1 from function , i want to know that which type of data they return string or list or json??

And also we get (dataProducts1=null), why this happen???In dataProducts i get the value...when i convert it json i get null value.....why????


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation