0

I'm trying to return the dataset value in the ajax method response. But I couldn't

I just returned as dataset but I'm unable to do it

Controller Code

public DataSet getDetailsBasedonSessionid(int sesson_id)
{
    using (SqlConnection conn = new SqlConnection(connstring))
    {
        DataSet ds = new DataSet();
        using (SqlCommand cmd = new SqlCommand("[dbo].[sGetUser]", conn))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@sesson_id", sesson_id);
            try
            {
                conn.Open();

                using (SqlDataAdapter adp = new SqlDataAdapter(cmd))
                {
                    adp.SelectCommand = cmd;
                    adp.Fill(ds);
                    DataTable dt1 = ds.Tables[0]; enter code here
                    DataTable dt2 = ds.Tables[1]; 
                }
                return ds;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
    return null;
}

View Code

function Score(){
    debugger;
    $.ajax({
        url: '@Url.Content("myurl")',
        type: 'GET',
        data: { sesson_id: '@ViewBag.Statement' },
        cache: false,
        async: false,
        success: function (result) {
            result.append(k);
        }
    });
}

I expect the output as First data of first table. But it doesn't return anything but it's running

barbsan
  • 3,418
  • 11
  • 21
  • 28

1 Answers1

-1

I haven't tested the code but it seems like your SQL Command is incomplete. I believe it should be something like SELECT * FROM sGetUser or whatever fields you would like. You are not selecting anything so your result is not returning anything.

  • CommandType is Storeprocedure right? It shouldn't be something you said – Ram Anugandula Jul 19 '19 at 08:23
  • Indeed is a Storeprocedure, I've missed that, apologies. Maybe this thread about how to return get return values from store procedures will help: https://stackoverflow.com/a/6210055/7380348 – Livio Tonini Jul 19 '19 at 08:32