Link to home
Start Free TrialLog in
Avatar of AlHal2
AlHal2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Basic Web API to view data

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

ASKER CERTIFIED SOLUTION
Avatar of AlHal2
AlHal2
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial