locked
how to get data from a given request forms RRS feed

  • Question

  • User1804579801 posted

    Iam getting data from request forms  in the below format

    1.key:foodsupport[] value:["50","Three Times","12","no"],["20","1 Time","4","no"],["10","2 Times","12","no"]

    now in the value i should take one by one value and insert into database 

    2key.:daterange value:Start Date of Requirement (Timed Requirement): 30/03/2020 End Date of Requirement (Timed Requirement): 15/04/2020 

    now i should take only the dates  30/03/2020 and  15/04/2020 

    Please suggest 

    Tuesday, March 31, 2020 5:15 AM

All replies

  • User753101303 posted

    Hi,

    Unclear. If posting from an HTML input form either using a submit button or Ajax (or even if it comes from some file or whatever) you have know formats allowing to forget about the underlying plumbing.

    For now it seems you are using JavaScript to gather input field values in hidden fields to get some custom format on your server ??? If yes, you are likely making things harder than to just just use what ASP.NET MVC offers out of the box.

    Tuesday, March 31, 2020 9:11 AM
  • User1804579801 posted

    No my request is user fills a form in jot form after submission it redirects to my .net thankyou page were iam fetching values from request forms and inserting into my database. Please suggest it is urgent 

    Tuesday, March 31, 2020 10:27 AM
  • User753101303 posted

    Keep in mind we have no way to know you are using a 3rd party product if you don't tell us.

    Then it is posted directly to your own ASP.NET form ? If posted I assume that rather than showing "raw" data it is already processed by some code? If Request.Form["value"] shows ["50","Three Times","12","no"],["20","1 Time","4","no"],["10","2 Times","12","no"] you could use a json library to parse this :

    using System;
    using System.Data;
    using System.Data.SqlClient;
    
    namespace ConsoleDemo
    {
        static class Program
        {
    
            static string[][]  JotFormArray(string value)
            {
                return Newtonsoft.Json.JsonConvert.DeserializeObject<string[][]>("[" + value + "]");
            }
            static void Main(string[] args)
            {
                var entry = @"[""50"", ""Three Times"", ""12"", ""no""],[""20"", ""1 Time"", ""4"", ""no""],[""10"", ""2 Times"", ""12"", ""no""]";
                var array = JotFormArray(entry);
                // Create a SQL statement
                var cmd = new SqlCommand("INSERT INTO MyTable(a,b,c,d) VALUES (@a,@b,@c,@d)");
                cmd.Parameters.Add("@a",SqlDbType.NVarChar);
                cmd.Parameters.Add("@b", SqlDbType.NVarChar);
                cmd.Parameters.Add("@c",SqlDbType.NVarChar);
                cmd.Parameters.Add("@d", SqlDbType.NVarChar);
                for (int i=0;i<array.Length;i++)
                {
                    for (int j=0;j<array[i].Length; j++)
                    {
                        // Populate parameters
                        cmd.Parameters[i].Value = array[i][j];
                        Console.WriteLine(array[i][j]);
                    }
                    // Run the query (of course you need to create a SqlConnection and so on...)
                    // cmd.ExecuteNonQuery();
                }
            }
        }
    }

    Or you could use "model binding" and "EF" if you know already about that. Assuming Jotform is using standard stuff it would allow to have ASP.NET parsing incoming form fields for you so that you can start your own code wiht having .NET objects and then using EF to store them rather than generating yourself SQL statements.

    You are not brand new to ASP.NET ?

    Edit: telling something is urgent is often considered rude. Most of us are just peers helping on our free time and more likely everyone posting here consider his own problem as urgent anyway...

    Tuesday, March 31, 2020 12:25 PM