We help IT Professionals succeed at work.

Basic Web API to view data

AlHal2
AlHal2 asked
on
57 Views
Last Modified: 2019-03-19
I'm writing a basic web API.  The code below is in the values controller and should put two rows from the data table into a JSON file.
How do I amend the code, so that it produces the file?
What URLs will work?

        public DataTable Get(string EmployeeName="Joe",string EmpCode="AR")
        {

                string ConnectionString = ConfigurationManager.ConnectionStrings["WebAPIDb"].ConnectionString;
                using (SqlConnection sqlCon = new SqlConnection())
                {
                    using (SqlCommand sqlcmd = new SqlCommand())
                    {
                        using (SqlDataAdapter sqladp = new SqlDataAdapter())
                        {
                            using (DataTable dt = new DataTable())
                            {
                                sqlCon.ConnectionString = ConnectionString;
                                sqlcmd.Connection = sqlCon;
                                sqlcmd.Parameters.Clear();
                                sqlcmd.CommandType = CommandType.StoredProcedure;
                                sqlcmd.CommandText = "EmployeeTable";
                                sqlcmd.Parameters.AddWithValue("@Operation", "S");
                                sqlcmd.Parameters.AddWithValue("@FirstName", "Joe");
                                sqlcmd.Parameters.AddWithValue("@Empcode", "AR");
                                sqladp.SelectCommand = sqlcmd;
                                sqladp.Fill(dt);
                                return dt;

                            }

                        }

                    }
                }

           

        }

Open in new window

Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.